This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: switch out pull-block for bl (#12)
- Loading branch information
1 parent
aa1b5ad
commit 4e5b618
Showing
5 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
karma: { | ||
browserNoActivityTimeout: 100 * 1000 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,50 @@ | ||
'use strict' | ||
|
||
const pullBlock = require('pull-block') | ||
const BufferList = require('bl') | ||
const through = require('pull-through') | ||
|
||
module.exports = (options) => { | ||
let maxSize = (typeof options === 'number') ? options : options.maxChunkSize | ||
return pullBlock(maxSize, { zeroPadding: false, emitEmpty: true }) | ||
let bl = new BufferList() | ||
let currentLength = 0 | ||
let emitted = false | ||
|
||
return through( | ||
function onData (buffer) { | ||
bl.append(buffer) | ||
|
||
currentLength += buffer.length | ||
|
||
while (currentLength >= maxSize) { | ||
this.queue(bl.slice(0, maxSize)) | ||
|
||
emitted = true | ||
|
||
// throw away consumed bytes | ||
if (maxSize === bl.length) { | ||
bl = new BufferList() | ||
currentLength = 0 | ||
} else { | ||
const newBl = new BufferList() | ||
newBl.append(bl.shallowSlice(maxSize)) | ||
bl = newBl | ||
|
||
// update our offset | ||
currentLength -= maxSize | ||
} | ||
} | ||
}, | ||
function onEnd () { | ||
if (currentLength) { | ||
this.queue(bl.slice(0, currentLength)) | ||
emitted = true | ||
} | ||
|
||
if (!emitted) { | ||
this.queue(Buffer.alloc(0)) | ||
} | ||
|
||
this.queue(null) | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters