Permalink
Browse files

Merge pull request #10 from tonistiigi/clone-buffer

Allow creating buffers from buffers
  • Loading branch information...
2 parents df655de + 68b2f74 commit 1b4302b5ad2ff443cc042f9a25b444e2ae2c26ae @toots committed Feb 27, 2013
Showing with 14 additions and 1 deletion.
  1. +6 −1 index.js
  2. +8 −0 test/buffer.js
View
@@ -359,7 +359,12 @@ function Buffer(subject, encoding, offset) {
// Treat array-ish objects as a byte array.
if (isArrayIsh(subject)) {
for (var i = 0; i < this.length; i++) {
- this.parent[i + this.offset] = subject[i];
+ if (subject instanceof Buffer) {
+ this.parent[i + this.offset] = subject.readUInt8(i);
+ }
+ else {
+ this.parent[i + this.offset] = subject[i];
+ }
}
} else if (type == 'string') {
// We are a string
View
@@ -119,3 +119,11 @@ test("concat() a varying number of buffers", function (t) {
t.equal(flatLongLen.toString(), (new Array(10+1).join('asdf')));
t.end();
});
+
+test("buffer from buffer", function (t) {
+ t.plan(1);
+ var b1 = new buffer.Buffer('asdf');
+ var b2 = new buffer.Buffer(b1);
+ t.equal(b1.toString('hex'), b2.toString('hex'));
+ t.end();
+});

0 comments on commit 1b4302b

Please sign in to comment.