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

Delta Between Two Patch Sets: lib/io.js

Issue 10296001: Implement File API (Closed)
Left Patch Set: Created April 12, 2013, 10:10 a.m.
Right Patch Set: Addressed the new issues Created April 16, 2013, 1:37 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/compat.js ('k') | libadblockplus.gyp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // 1 //
2 // No direct file system access, using FileSystem API 2 // No direct file system access, using FileSystem API
3 // 3 //
4 4
5 var IO = exports.IO = 5 var IO = exports.IO =
6 { 6 {
7 lineBreak: "\n", 7 lineBreak: "\n",
8 8
9 resolveFilePath: function(path) 9 resolveFilePath: function(path)
10 { 10 {
(...skipping 23 matching lines...) Expand all
34 for (var i = 0; i < lines.length; i++) 34 for (var i = 0; i < lines.length; i++)
35 listener.process(lines[i]); 35 listener.process(lines[i]);
36 listener.process(null); 36 listener.process(null);
37 callback(null); 37 callback(null);
38 } 38 }
39 }); 39 });
40 }, 40 },
41 41
42 writeToFile: function(file, encode, data, callback, timeLineID) 42 writeToFile: function(file, encode, data, callback, timeLineID)
43 { 43 {
44 var blob; 44 var content = data.join(this.lineBreak) + this.lineBreak;
45 try 45 _fileSystem.write(file, content, callback);
46 {
47 blob = new Blob([data.join(this.lineBreak) + this.lineBreak], {type: "text /plain"});
48 }
49 catch (e)
50 {
51 if (!(e instanceof TypeError))
52 throw e;
53
54 // Blob wasn't a constructor before Chrome 20
55 var builder = new (window.BlobBuilder || window.WebKitBlobBuilder);
56 builder.append(data.join(this.lineBreak) + this.lineBreak);
57 blob = builder.getBlob("text/plain");
58 }
59
60 _fileSystem.write(file, blob, callback);
61 }, 46 },
62 47
63 copyFile: function(fromFile, toFile, callback) 48 copyFile: function(fromFile, toFile, callback)
64 { 49 {
65 // Simply combine read and write operations 50 // Simply combine read and write operations
66 var data = []; 51 var data = [];
67 this.readFromFile(fromFile, false, { 52 this.readFromFile(fromFile, false, {
68 process: function(line) 53 process: function(line)
69 { 54 {
70 if (line !== null) 55 if (line !== null)
(...skipping 16 matching lines...) Expand all
87 removeFile: function(file, callback) 72 removeFile: function(file, callback)
88 { 73 {
89 _fileSystem.remove(file, callback); 74 _fileSystem.remove(file, callback);
90 }, 75 },
91 76
92 statFile: function(file, callback) 77 statFile: function(file, callback)
93 { 78 {
94 _fileSystem.stat(file, callback); 79 _fileSystem.stat(file, callback);
95 } 80 }
96 }; 81 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld