Skip to content

Commit

Permalink
don't end the stream
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Dec 22, 2014
1 parent f2b6857 commit 261c989
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ var through = require("through2")
module.exports = function (start, end) {
end += 1
var bytesReceived = 0
var lastByteFound = false

return through(function (chunk, enc, next) {
bytesReceived += chunk.length

if (bytesReceived >= start) {
if (!lastByteFound && bytesReceived >= start) {
if (start - (bytesReceived - chunk.length) > 0)
chunk = chunk.slice(start - (bytesReceived - chunk.length))

if (end <= bytesReceived) {
this.push(chunk.slice(0, chunk.length - (bytesReceived - end)))
this.end()
lastByteFound = true
} else
this.push(chunk)
}
Expand Down

0 comments on commit 261c989

Please sign in to comment.