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. 21, 2012, 1:16 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
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";
Wladimir Palant 2012/09/21 15:36:18 Looking at that again - you shouldn't need the con
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

Powered by Google App Engine
This is Rietveld