Skip to content

Commit e5099ac

Browse files
committed
fixes tests with block-stream2
1 parent ae25302 commit e5099ac

File tree

2 files changed

+4
-43
lines changed

2 files changed

+4
-43
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"homepage": "https://github.com/diasdavid/js-ipfs-data-importing#readme",
2929
"devDependencies": {
30+
"block-stream2": "^1.1.0",
3031
"brfs": "^1.4.3",
3132
"bs58": "^3.0.0",
3233
"buffer-loader": "0.0.1",

src/chunker-fixed-size.js

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,5 @@
1-
var through2 = require('through2')
1+
var chunker = require('block-stream2')
22

3-
exports = module.exports = FixedSizeChunker
4-
5-
// The difference of this chunker compared to other fixed size chunkers
6-
// available, is that it doesn't add padding the last chunk
7-
8-
function FixedSizeChunker (size) {
9-
var stream = through2(transform, flush)
10-
11-
var buf = new Buffer(0)
12-
13-
function transform (chunk, enc, cb) {
14-
var that = this
15-
16-
buf = Buffer.concat([buf, chunk])
17-
18-
if (buf.length >= size) {
19-
slice()
20-
}
21-
22-
function slice () {
23-
var chunk = new Buffer(size, 'binary')
24-
var newBuf = new Buffer(buf.length - size, 'binary')
25-
buf.copy(chunk, 0, 0, size)
26-
buf.copy(newBuf, 0, size, buf.length)
27-
buf = newBuf
28-
that.push(chunk)
29-
30-
if (buf.length >= size) {
31-
return slice()
32-
}
33-
}
34-
35-
cb()
36-
}
37-
38-
function flush (cb) {
39-
// last chunk
40-
this.push(buf)
41-
cb()
42-
}
43-
44-
return stream
3+
exports = module.exports = function (size) {
4+
return chunker({ size: size, zeroPadding: false })
455
}

0 commit comments

Comments
 (0)