-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also, ported all filesystem tests to Jasmine.
- Loading branch information
Showing
44 changed files
with
1,246 additions
and
758 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
var Q = require("q"); | ||
var Reader = require("./reader"); | ||
|
||
module.exports = BufferStream; | ||
function BufferStream(chunks, charset) { | ||
if (!(this instanceof BufferStream)) { | ||
return new BufferStream(chunks, charset); | ||
} | ||
if (!chunks) { | ||
chunks = []; | ||
} else if (!Array.isArray(chunks)) { | ||
chunks = [chunks]; | ||
} | ||
this._charset = charset; | ||
this._chunks = chunks; | ||
this._close = Q.defer(); | ||
this.closed = this._close.promise; | ||
} | ||
|
||
BufferStream.prototype.forEach = function (write, thisp) { | ||
var self = this; | ||
var chunks = self._chunks; | ||
return Q.fcall(function () { | ||
chunks.splice(0, chunks.length).forEach(write, thisp); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
}); | ||
}; | ||
|
||
BufferStream.prototype.read = function () { | ||
var result; | ||
result = Reader.join(this._chunks); | ||
if (this._charset) { | ||
result = result.toString(this._charset); | ||
} | ||
return Q.resolve(result); | ||
}; | ||
|
||
BufferStream.prototype.write = function (chunk) { | ||
if (this._charset) { | ||
chunk = new Buffer(String(chunk), this._charset); | ||
} else { | ||
if (!(chunk instanceof Buffer)) { | ||
throw new Error("Can't write strings to buffer stream without a charset: " + chunk); | ||
} | ||
} | ||
this._chunks.push(chunk); | ||
return Q.resolve(); | ||
}; | ||
|
||
BufferStream.prototype.close = function () { | ||
this._close.resolve(); | ||
return Q.resolve(); | ||
}; | ||
|
||
BufferStream.prototype.destroy = function () { | ||
this._close.resolve(); | ||
return Q.resolve(); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
This is causing File.chunk passed to BufferStream to be cleared by reference.
Resulting in serving empty response the second time if using joey+MockFs.
I dont think "chunks.splice" is needed.
@kriskowal