dat-storage
dat-storage copied to clipboard
issue with { indexing: true }
This fails:
const fs = require('fs')
const hyperdrive = require('hyperdrive')
const src = `/tmp/${Math.random()}/`
console.log(src)
const storage = require('dat-storage')(src)
const archive = hyperdrive(storage, { latest: true, indexing: true })
archive.writeFile('/dat.json', 'hi', err => {
if (err) throw err // => ok
console.log(fs.readFileSync(`${src}/dat.json`)) // => empty
archive.readFile('/dat.json', (err, data) => {
if (err) throw err // => error (couldn't satisfy length)
console.log('data', data)
})
})
with message
Error: Could not satisfy length
at onread (/Users/julian/dev/datproject/multidat/node_modules/random-access-file/index.js:122:17)
The file on disk is also empty - although it exists.
The snippet can by fixed by setting { indexing: false }.
I'm not sure yet what's going on here but this makes multidat tests fail for example.
Dat-node is a library that sets { latest: true, indexing: true }, and this is where the issue was discovered:
const fs = require('fs')
const src = `/tmp/${Math.random()}/`
console.log(src)
Dat(src, (err, dat) => {
if (err) throw err
dat.archive.writeFile('/dat.json', Buffer.from('hi'), err => {
if (err) throw err
console.log(fs.readFileSync(`${src}/dat.json`)) // => empty
dat.archive.readFile('/dat.json', (err, data) => {
if (err) throw err // => error (couldn't satisfy length)
})
})
})
Above fails with the same error.
More information on this hyperdrive issue: https://github.com/mafintosh/hyperdrive/issues/160 and started a PR to fix some of it: https://github.com/mafintosh/hyperdrive/pull/186.