OLD | NEW |
1 Cu.import("resource://gre/modules/FileUtils.jsm"); | 1 Cu.import("resource://gre/modules/FileUtils.jsm"); |
2 | 2 |
3 let outputStream; | 3 let outputStream; |
4 let converterOutputStream; | 4 let converterOutputStream; |
5 | 5 |
6 function createTemporaryFile(name) | 6 function createTemporaryFile(name) |
7 { | 7 { |
8 let file = FileUtils.getFile("TmpD", [name]); | 8 let file = FileUtils.getFile("TmpD", [name]); |
9 file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); | 9 file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); |
10 return file; | 10 return file; |
11 } | 11 } |
12 | 12 |
13 function openOutputStream(file) | 13 function openOutputStream(file) |
14 { | 14 { |
15 let outputStream = FileUtils.openSafeFileOutputStream(file); | 15 let outputStream = FileUtils.openSafeFileOutputStream(file); |
16 let converterOutputStream = Cc["@mozilla.org/intl/converter-output-stream;1"] | 16 let converterOutputStream = Cc["@mozilla.org/intl/converter-output-stream;1"] |
17 .createInstance(Ci.nsIConverterOutputStream); | 17 .createInstance(Ci.nsIConverterOutputStream); |
18 converterOutputStream.init(outputStream, "UTF-8", 0, 0); | 18 converterOutputStream.init(outputStream, "UTF-8", 0, 0); |
19 return [outputStream, converterOutputStream]; | 19 return [outputStream, converterOutputStream]; |
20 } | 20 } |
21 | 21 |
22 let Storage = exports.Storage = {}; | 22 let Storage = exports.Storage = {}; |
23 | 23 |
24 Storage.init = function() | 24 Storage.init = function() |
25 { | 25 { |
26 Storage.dataFile = createTemporaryFile("crawler-data"); | 26 Storage.requestsFile = createTemporaryFile("crawler-requests"); |
27 [outputStream, converterOutputStream] = openOutputStream(Storage.dataFile); | 27 [outputStream, converterOutputStream] = |
| 28 openOutputStream(Storage.requestsFile); |
28 }; | 29 }; |
29 | 30 |
30 Storage.write = function(data) | 31 Storage.write = function(data) |
31 { | 32 { |
32 let line = JSON.stringify(data) + "\n"; | 33 let line = JSON.stringify(data) + "\n"; |
33 converterOutputStream.writeString(line); | 34 converterOutputStream.writeString(line); |
34 }; | 35 }; |
35 | 36 |
36 Storage.finish = function() | 37 Storage.finish = function() |
37 { | 38 { |
38 converterOutputStream.flush(); | 39 converterOutputStream.flush(); |
39 FileUtils.closeSafeFileOutputStream(outputStream); | 40 FileUtils.closeSafeFileOutputStream(outputStream); |
40 }; | 41 }; |
41 | 42 |
42 Storage.destroy = function() | 43 Storage.destroy = function() |
43 { | 44 { |
44 Storage.dataFile.remove(true); | 45 Storage.requestsFile.remove(true); |
45 }; | 46 }; |
OLD | NEW |