holepunchto / hyperdrive

Hyperdrive is a secure, real time distributed file system
Apache License 2.0
1.86k stars 135 forks source link

Calling download() with no path: TypeError: expected a string #309

Closed 4c656554 closed 2 years ago

4c656554 commented 3 years ago

Expected: calling download() with no path should download all files. Presently getting following error (node v14.15.5, ubuntu):

Actual:

const Hyperdrive = require('hyperdrive')

let d = new Hyperdrive('hyper://778f8d955175c92e4ced5e4f5563f69bfec0c86cc6f670352c457943666fe639')

d.download()

Gives the following error:

/myPath/node_modules/normalize-path/index.js:13
    throw new TypeError('expected a string');
    ^

TypeError: expected a string
    at normalizePath (/myPath/node_modules/normalize-path/index.js:13:11)
    at unixify (/myPath/node_modules/unixify/index.js:13:14)
    at fixName (/myPath/node_modules/hyperdrive/index.js:1292:10)
    at HyperdriveCompat.lstat (/myPath/node_modules/hyperdrive/index.js:712:12)
    at HyperdriveCompat.stat (/myPath/node_modules/hyperdrive/index.js:741:10)
    at HyperdriveCompat.stat (/myPath/node_modules/hyperdrive/index.js:738:49)
    at HyperdriveCompat._walk (/myPath/node_modules/hyperdrive/index.js:1057:10)
    at HyperdriveCompat.download (/myPath/node_modules/hyperdrive/index.js:1040:17)
    at Object.<anonymous> (/myPath/reptest.js:6:3)

From the docs:

If no path is specified this will download all files.

https://github.com/hypercore-protocol/hyperdrive#drivedownloadpath-callback

4c656554 commented 3 years ago

I think a fix could be to check for undefined in line 1039 of index.js:

if (path === undefined) path = '/'

mixmix commented 3 years ago

that or change the docs to say:

to download all files set path to /

mixmix commented 2 years ago

Sweet!