зеркало из https://github.com/mozilla/gecko-dev.git
Bug 928340 - Using nsIAsyncStreamCopier2 instead of nsIAsyncStreamCopier in NetUtil.asyncCopy. r=mayhemer
This commit is contained in:
Родитель
b12935d64a
Коммит
301344549d
|
@ -43,7 +43,8 @@ this.NetUtil = {
|
|||
* can be used to cancel the copying). The consumer can ignore the
|
||||
* return value if desired.
|
||||
*/
|
||||
asyncCopy: function NetUtil_asyncCopy(aSource, aSink, aCallback)
|
||||
asyncCopy: function NetUtil_asyncCopy(aSource, aSink,
|
||||
aCallback = null)
|
||||
{
|
||||
if (!aSource || !aSink) {
|
||||
let exception = new Components.Exception(
|
||||
|
@ -54,28 +55,13 @@ this.NetUtil = {
|
|||
throw exception;
|
||||
}
|
||||
|
||||
var sourceBuffered = ioUtil.inputStreamIsBuffered(aSource);
|
||||
var sinkBuffered = ioUtil.outputStreamIsBuffered(aSink);
|
||||
|
||||
var ostream = aSink;
|
||||
if (!sourceBuffered && !sinkBuffered) {
|
||||
// wrap the sink in a buffered stream.
|
||||
ostream = Cc["@mozilla.org/network/buffered-output-stream;1"].
|
||||
createInstance(Ci.nsIBufferedOutputStream);
|
||||
ostream.init(aSink, 0x8000);
|
||||
sinkBuffered = true;
|
||||
}
|
||||
|
||||
// make a stream copier
|
||||
var copier = Cc["@mozilla.org/network/async-stream-copier;1"].
|
||||
createInstance(Ci.nsIAsyncStreamCopier);
|
||||
|
||||
// Initialize the copier. The 0x8000 should match the size of the
|
||||
// buffer our buffered stream is using, for best performance. If we're
|
||||
// not using our own buffered stream, that's ok too. But maybe we
|
||||
// should just use the default net segment size here?
|
||||
copier.init(aSource, ostream, null, sourceBuffered, sinkBuffered,
|
||||
0x8000, true, true);
|
||||
createInstance(Ci.nsIAsyncStreamCopier2);
|
||||
copier.init(aSource, aSink,
|
||||
null /* Default event target */,
|
||||
0 /* Default length */,
|
||||
true, true /* Auto-close */);
|
||||
|
||||
var observer;
|
||||
if (aCallback) {
|
||||
|
@ -90,7 +76,7 @@ this.NetUtil = {
|
|||
}
|
||||
|
||||
// start the copying
|
||||
copier.asyncCopy(observer, null);
|
||||
copier.QueryInterface(Ci.nsIAsyncStreamCopier).asyncCopy(observer, null);
|
||||
return copier;
|
||||
},
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче