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

Unified Diff: lib/io.js

Issue 6083164824928256: Issue 1510 - Stop using OS.File.readTo() (Closed)
Patch Set: Created Oct. 30, 2014, 10:03 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/io.js
===================================================================
--- a/lib/io.js
+++ b/lib/io.js
@@ -23,17 +23,17 @@ let {Services} = Cu.import("resource://g
let {FileUtils} = Cu.import("resource://gre/modules/FileUtils.jsm", null);
let {OS} = Cu.import("resource://gre/modules/osfile.jsm", null);
let {Task} = Cu.import("resource://gre/modules/Task.jsm", null);
let {Prefs} = require("prefs");
let {Utils} = require("utils");
let firstRead = true;
-const BUFFER_SIZE = 0x8000; // 32kB
+const BUFFER_SIZE = 0x80000; // 512kB
let IO = exports.IO =
{
/**
* Retrieves the platform-dependent line break string.
*/
get lineBreak()
{
@@ -145,17 +145,16 @@ let IO = exports.IO =
error = e;
return;
}
callback(e);
};
let decoder = new TextDecoder();
- let array = new Uint8Array(BUFFER_SIZE);
Task.spawn(function()
{
if (firstRead && Services.vc.compare(Utils.platformVersion, "23.0a1") <= 0)
{
// See https://issues.adblockplus.org/ticket/530 - the first file
// opened cannot be closed due to Gecko bug 858723. Make sure that
// our patterns.ini file doesn't stay locked by opening a dummy file
// first.
@@ -168,29 +167,25 @@ let IO = exports.IO =
catch (e)
{
// Dummy might be locked already, we don't care
}
}
firstRead = false;
let f = yield OS.File.open(file.path, {read: true});
- let numBytes;
- do
+ while (true)
{
- numBytes = yield f.readTo(array);
- if (numBytes)
- {
- let data = decoder.decode(numBytes == BUFFER_SIZE ?
- array :
- array.subarray(0, numBytes), {stream: true});
- onProgress(data);
- }
- } while (numBytes);
+ let array = yield f.read(BUFFER_SIZE);
+ if (!array.length)
+ break;
+ let data = decoder.decode(array, {stream: true});
+ onProgress(data);
+ }
yield f.close();
}.bind(this)).then(onSuccess, onError);
}
catch (e)
{
callback(e);
}
},
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld