Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/storage.js

Issue 8402021: Crawler frontend (Closed)
Patch Set: Created Sept. 26, 2012, 8:25 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/main.js ('k') | metadata » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 Cu.import("resource://gre/modules/FileUtils.jsm");
2
3 let outputStream;
4 let converterOutputStream;
5
6 function createTemporaryFile(name)
7 {
8 let file = FileUtils.getFile("TmpD", [name]);
9 file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
10 return file;
11 }
12
13 function openOutputStream(file)
14 {
15 let outputStream = FileUtils.openSafeFileOutputStream(file);
16 let converterOutputStream = Cc["@mozilla.org/intl/converter-output-stream;1"]
17 .createInstance(Ci.nsIConverterOutputStream);
18 converterOutputStream.init(outputStream, "UTF-8", 0, 0);
19 return [outputStream, converterOutputStream];
20 }
21
22 let Storage = exports.Storage = {};
23
24 Storage.init = function()
25 {
26 Storage.dataFile = createTemporaryFile("crawler-data");
27 [outputStream, converterOutputStream] = openOutputStream(Storage.dataFile);
28 };
29
30 Storage.write = function(data)
31 {
32 let line = JSON.stringify(data) + "\n";
33 converterOutputStream.writeString(line);
34 };
35
36 Storage.finish = function()
37 {
38 converterOutputStream.flush();
39 FileUtils.closeSafeFileOutputStream(outputStream);
40 };
41
42 Storage.destroy = function()
43 {
44 Storage.dataFile.remove(true);
45 };
OLDNEW
« no previous file with comments | « lib/main.js ('k') | metadata » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld