Comparing version 0.0.15 to 0.0.16
{ | ||
"name": "q-io", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "Q Promise wrappers for Node's IO.", | ||
@@ -19,3 +19,3 @@ "homepage": "http://github.com/kriskowal/q-io/", | ||
"dependencies": { | ||
"q": "0.8.8" | ||
"q": "0.8.x" | ||
}, | ||
@@ -22,0 +22,0 @@ "repository": { |
44
q-io.js
@@ -46,17 +46,13 @@ | ||
begin.resolve(self); | ||
if (receiver) | ||
if (receiver) { | ||
receiver(chunk); | ||
else | ||
} else { | ||
chunks.push(chunk); | ||
} | ||
}); | ||
function slurp() { | ||
if (charset) { | ||
var result = chunks.join(""); | ||
chunks = []; | ||
return result; | ||
} else { | ||
consolidate(chunks); | ||
return chunks.shift(); | ||
} | ||
var result = join(chunks, charset); | ||
chunks.splice(0, chunks.length); | ||
return result; | ||
} | ||
@@ -73,6 +69,5 @@ | ||
var deferred = Q.defer(); | ||
Q.when(end.promise, function () { | ||
Q.done(end.promise, function () { | ||
deferred.resolve(slurp()); | ||
}) | ||
.end() | ||
}); | ||
return deferred.promise; | ||
@@ -139,3 +134,3 @@ }; | ||
if (!_stream.writeable && !_stream.writable) | ||
return Q.reject("Stream not writable"); | ||
return Q.reject(new Error("Can't write to non-writable (possibly closed) stream")); | ||
if (!_stream.write(content)) { | ||
@@ -188,4 +183,4 @@ return drained.promise; | ||
exports.consolidate = consolidate; | ||
function consolidate(buffers) { | ||
exports.join = join; | ||
function join(buffers) { | ||
var length = 0; | ||
@@ -209,3 +204,20 @@ var at; | ||
buffers.splice(0, ii, result); | ||
return result; | ||
} | ||
/* | ||
Reads an entire forEachable stream of buffers and returns a single buffer. | ||
*/ | ||
exports.read = read; | ||
function read(stream, charset) { | ||
var chunks = []; | ||
stream.forEach(function (chunk) { | ||
chunks.push(chunk); | ||
}); | ||
if (charset) { | ||
return chunks.join(""); | ||
} else { | ||
return join(chunks); | ||
} | ||
} | ||
@@ -0,1 +1,2 @@ | ||
var Q = require("q"); | ||
@@ -2,0 +3,0 @@ var FS = require("q-fs"); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8859
209