Skip to content
This repository was archived by the owner on Aug 12, 2020. It is now read-only.

Commit bef3152

Browse files
committed
fix: make rabin an optional dependency
There are no pre-built binaries currently provided so it does not work on systems that do not have suitable build tools installed, eg. Windows out of the box.
1 parent caf93ed commit bef3152

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@
7272
"pull-through": "^1.0.18",
7373
"pull-traverse": "^1.0.3",
7474
"pull-write": "^1.1.4",
75-
"rabin": "^1.6.0",
7675
"sparse-array": "^1.3.1",
7776
"stream-to-pull-stream": "^1.7.2"
7877
},
78+
"optionalDependencies": {
79+
"rabin": "^1.6.0"
80+
},
7981
"contributors": [
8082
"Alan Shaw <[email protected]>",
8183
"Arpit Agarwal <[email protected]>",

src/builder/builder.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,20 @@ module.exports = function builder (createChunker, ipld, createReducer, _options)
105105
}
106106

107107
const reducer = createReducer(reduce(file, ipld, options), options)
108+
let chunker
109+
110+
try {
111+
chunker = createChunker(options.chunkerOptions)
112+
} catch (error) {
113+
return callback(error)
114+
}
108115

109116
let previous
110117
let count = 0
111118

112119
pull(
113120
file.content,
114-
createChunker(options.chunkerOptions),
121+
chunker,
115122
pull.map(chunk => {
116123
if (options.progress && typeof options.progress === 'function') {
117124
options.progress(chunk.byteLength)

src/chunker/rabin.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
'use strict'
22

3-
const createRabin = require('rabin')
43
const toPull = require('stream-to-pull-stream')
54

5+
let createRabin
6+
67
module.exports = (options) => {
8+
if (!createRabin) {
9+
try {
10+
createRabin = require('rabin')
11+
} catch (error) {
12+
error.message = `Rabin chunker not supported, it may have failed to install - ${error.message}`
13+
14+
throw error
15+
}
16+
}
17+
718
let min, max, avg
819
if (options.minChunkSize && options.maxChunkSize && options.avgChunkSize) {
920
avg = options.avgChunkSize

0 commit comments

Comments
 (0)