summaryrefslogtreecommitdiff
path: root/data/extensions/spyblock@gnu.org/lib/io.js
diff options
context:
space:
mode:
Diffstat (limited to 'data/extensions/spyblock@gnu.org/lib/io.js')
-rw-r--r--data/extensions/spyblock@gnu.org/lib/io.js61
1 files changed, 14 insertions, 47 deletions
diff --git a/data/extensions/spyblock@gnu.org/lib/io.js b/data/extensions/spyblock@gnu.org/lib/io.js
index ea362b7..5e60b54 100644
--- a/data/extensions/spyblock@gnu.org/lib/io.js
+++ b/data/extensions/spyblock@gnu.org/lib/io.js
@@ -1,6 +1,6 @@
/*
- * This file is part of Adblock Plus <http://adblockplus.org/>,
- * Copyright (C) 2006-2014 Eyeo GmbH
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-2015 Eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
@@ -24,12 +24,11 @@ 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 {TimeLine} = require("timeline");
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 =
{
@@ -39,9 +38,8 @@ let IO = exports.IO =
get lineBreak()
{
let lineBreak = (Services.appinfo.OS == "WINNT" ? "\r\n" : "\n");
- delete IO.lineBreak;
- IO.__defineGetter__("lineBreak", () => lineBreak);
- return IO.lineBreak;
+ Object.defineProperty(this, "lineBreak", {value: lineBreak});
+ return lineBreak;
},
/**
@@ -71,7 +69,7 @@ let IO = exports.IO =
* each line read and with a null parameter once the read operation is done.
* The callback will be called when the operation is done.
*/
- readFromFile: function(/**nsIFile*/ file, /**Object*/ listener, /**Function*/ callback, /**String*/ timeLineID)
+ readFromFile: function(/**nsIFile*/ file, /**Object*/ listener, /**Function*/ callback)
{
try
{
@@ -82,11 +80,6 @@ let IO = exports.IO =
let onProgress = function(data)
{
- if (timeLineID)
- {
- TimeLine.asyncStart(timeLineID);
- }
-
let index = (processing ? -1 : Math.max(data.lastIndexOf("\n"), data.lastIndexOf("\r")));
if (index >= 0)
{
@@ -126,11 +119,6 @@ let IO = exports.IO =
}
else
buffer += data;
-
- if (timeLineID)
- {
- TimeLine.asyncEnd(timeLineID);
- }
};
let onSuccess = function()
@@ -142,21 +130,10 @@ let IO = exports.IO =
return;
}
- if (timeLineID)
- {
- TimeLine.asyncStart(timeLineID);
- }
-
if (buffer !== "")
listener.process(buffer);
listener.process(null);
- if (timeLineID)
- {
- TimeLine.asyncEnd(timeLineID);
- TimeLine.asyncDone(timeLineID);
- }
-
callback(null);
};
@@ -170,15 +147,9 @@ let IO = exports.IO =
}
callback(e);
-
- if (timeLineID)
- {
- TimeLine.asyncDone(timeLineID);
- }
};
let decoder = new TextDecoder();
- let array = new Uint8Array(BUFFER_SIZE);
Task.spawn(function()
{
if (firstRead && Services.vc.compare(Utils.platformVersion, "23.0a1") <= 0)
@@ -201,19 +172,15 @@ let IO = exports.IO =
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);
}
@@ -227,7 +194,7 @@ let IO = exports.IO =
* Writes string data to a file in UTF-8 format asynchronously. The callback
* will be called when the write operation is done.
*/
- writeToFile: function(/**nsIFile*/ file, /**Iterator*/ data, /**Function*/ callback, /**String*/ timeLineID)
+ writeToFile: function(/**nsIFile*/ file, /**Iterator*/ data, /**Function*/ callback)
{
try
{