1 /* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 function write_atomic(file
, str
) {
9 "@mozilla.org/network/atomic-file-output-stream;1"
10 ].createInstance(Ci
.nsIFileOutputStream
);
11 stream
.init(file
, -1, -1, 0);
13 var written
= stream
.write(str
, str
.length
);
14 if (written
== str
.length
) {
17 str
= str
.substring(written
);
19 stream
.QueryInterface(Ci
.nsISafeOutputStream
).finish();
23 function write(file
, str
) {
25 "@mozilla.org/network/safe-file-output-stream;1"
26 ].createInstance(Ci
.nsIFileOutputStream
);
27 stream
.init(file
, -1, -1, 0);
29 var written
= stream
.write(str
, str
.length
);
30 if (written
== str
.length
) {
33 str
= str
.substring(written
);
35 stream
.QueryInterface(Ci
.nsISafeOutputStream
).finish();
39 function checkFile(file
, str
) {
40 var stream
= Cc
["@mozilla.org/network/file-input-stream;1"].createInstance(
43 stream
.init(file
, -1, -1, 0);
45 var scriptStream
= Cc
["@mozilla.org/scriptableinputstream;1"].createInstance(
46 Ci
.nsIScriptableInputStream
48 scriptStream
.init(stream
);
50 Assert
.equal(scriptStream
.read(scriptStream
.available()), str
);
55 var filename
= "\u0913";
56 var file
= Services
.dirsvc
.get("TmpD", Ci
.nsIFile
);
57 file
.append(filename
);
59 write(file
, "First write");
60 checkFile(file
, "First write");
62 write(file
, "Second write");
63 checkFile(file
, "Second write");
65 write_atomic(file
, "First write: Atomic");
66 checkFile(file
, "First write: Atomic");
68 write_atomic(file
, "Second write: Atomic");
69 checkFile(file
, "Second write: Atomic");