Skip to content

Commit

Permalink
Merge pull request #44 from yuri-kilochek/master
Browse files Browse the repository at this point in the history
`shallowSlice` fix
  • Loading branch information
mcollina authored May 1, 2017
2 parents 199e5c1 + d4e4e1c commit 391fd88
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bl.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ BufferList.prototype.shallowSlice = function shallowSlice (start, end) {
, endOffset = this._offset(end)
, buffers = this._bufs.slice(startOffset[0], endOffset[0] + 1)

if (startOffset[1] != 0)
buffers[0] = buffers[0].slice(startOffset[1])

if (endOffset[1] == 0)
buffers.pop()
else
buffers[buffers.length-1] = buffers[buffers.length-1].slice(0, endOffset[1])

if (startOffset[1] != 0)
buffers[0] = buffers[0].slice(startOffset[1])

return new BufferList(buffers)
}

Expand Down
2 changes: 2 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,11 @@ tape('shallow slice across buffer boundaries', function (t) {
})

tape('shallow slice within single buffer', function (t) {
t.plan(2)
var bl = new BufferList(['First', 'Second', 'Third'])

t.equal(bl.shallowSlice(5, 10).toString(), 'Secon')
t.equal(bl.shallowSlice(7, 10).toString(), 'con')
t.end()
})

Expand Down

0 comments on commit 391fd88

Please sign in to comment.