Permalink
Browse files

Improve support for binary data

  • Loading branch information...
ducarroz committed Apr 30, 2013
1 parent f44ccc8 commit 572c2e09cde8466f8a112fceab1e9bed28dbe1b4
Showing with 9 additions and 2 deletions.
  1. +6 −2 fs-common.js
  2. +3 −0 writer.js
View
@@ -66,8 +66,12 @@ exports.update = function (exports, workingDirectory) {
options.flags = flags;
options.charset = charset;
}
- flags = "w" + (options.flags || "").replace(/[wb]/g, "");
- if (content instanceof Buffer) {
+ flags = "w" + (options.flags || "").replace(/[w]/g, "");
+ if (flags.indexOf("b") !== -1) {
+ if (!(content instanceof Buffer)) {
+ content = new Buffer(content);
+ }
+ } else if (content instanceof Buffer) {
flags += "b";
}
options.flags = flags;
View
@@ -40,6 +40,9 @@ function Writer(_stream, charset) {
self.write = function (content) {
if (!_stream.writeable && !_stream.writable)
return Q.reject(new Error("Can't write to non-writable (possibly closed) stream"));
+ if (_stream.encoding == "binary" && !(content instanceof Buffer)) {
+ content = new Buffer(content);
+ }
if (!_stream.write(content)) {
return drained.promise;
} else {

0 comments on commit 572c2e0

Please sign in to comment.