Default value for second arg of Buffer#slice
This commit is contained in:
parent
4fe3007a1a
commit
77fc61d539
@ -175,7 +175,7 @@ into `buf2`, starting at the 8th byte in `buf2`.
|
|||||||
// !!!!!!!!qrst!!!!!!!!!!!!!
|
// !!!!!!!!qrst!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
|
||||||
### buffer.slice(start, end)
|
### buffer.slice(start, end=buffer.length)
|
||||||
|
|
||||||
Returns a new buffer which references the
|
Returns a new buffer which references the
|
||||||
same memory as the old, but offset and cropped by the `start` and `end`
|
same memory as the old, but offset and cropped by the `start` and `end`
|
||||||
|
@ -322,12 +322,9 @@ Buffer.prototype.copy = function copy (target, target_start, start, end) {
|
|||||||
|
|
||||||
// slice(start, end)
|
// slice(start, end)
|
||||||
Buffer.prototype.slice = function (start, end) {
|
Buffer.prototype.slice = function (start, end) {
|
||||||
if (end > this.length) {
|
if (!end) end = this.length;
|
||||||
throw new Error("oob");
|
if (end > this.length) throw new Error("oob");
|
||||||
}
|
if (start > end) throw new Error("oob");
|
||||||
if (start > end) {
|
|
||||||
throw new Error("oob");
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Buffer(this.parent, end - start, +start + this.offset);
|
return new Buffer(this.parent, end - start, +start + this.offset);
|
||||||
};
|
};
|
||||||
|
@ -312,3 +312,9 @@ for (i = 0; i < l; i++) {
|
|||||||
sb = b.toString();
|
sb = b.toString();
|
||||||
assert.equal(sb.length, s.length);
|
assert.equal(sb.length, s.length);
|
||||||
assert.equal(sb, s);
|
assert.equal(sb, s);
|
||||||
|
|
||||||
|
|
||||||
|
// Single argument slice
|
||||||
|
b = new Buffer("abcde");
|
||||||
|
assert.equal("bcde", b.slice(1).toString());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user