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

Commit

Permalink
fix: make rabin an optional dependency
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
achingbrain committed Aug 11, 2018
1 parent caf93ed commit bef3152
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@
"pull-through": "^1.0.18",
"pull-traverse": "^1.0.3",
"pull-write": "^1.1.4",
"rabin": "^1.6.0",
"sparse-array": "^1.3.1",
"stream-to-pull-stream": "^1.7.2"
},
"optionalDependencies": {
"rabin": "^1.6.0"
},
"contributors": [
"Alan Shaw <alan@tableflip.io>",
"Arpit Agarwal <atvanguard@users.noreply.github.com>",
Expand Down
9 changes: 8 additions & 1 deletion src/builder/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,20 @@ module.exports = function builder (createChunker, ipld, createReducer, _options)
}

const reducer = createReducer(reduce(file, ipld, options), options)
let chunker

try {
chunker = createChunker(options.chunkerOptions)
} catch (error) {
return callback(error)
}

let previous
let count = 0

pull(
file.content,
createChunker(options.chunkerOptions),
chunker,
pull.map(chunk => {
if (options.progress && typeof options.progress === 'function') {
options.progress(chunk.byteLength)
Expand Down
13 changes: 12 additions & 1 deletion src/chunker/rabin.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
'use strict'

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

let createRabin

module.exports = (options) => {
if (!createRabin) {
try {
createRabin = require('rabin')
} catch (error) {
error.message = `Rabin chunker not supported, it may have failed to install - ${error.message}`

throw error
}
}

let min, max, avg
if (options.minChunkSize && options.maxChunkSize && options.avgChunkSize) {
avg = options.avgChunkSize
Expand Down

0 comments on commit bef3152

Please sign in to comment.