Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

issue with { indexing: true } #7

Open
juliangruber opened this issue Jan 26, 2018 · 2 comments
Open

issue with { indexing: true } #7

juliangruber opened this issue Jan 26, 2018 · 2 comments
Labels

Comments

@juliangruber
Copy link

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.

@juliangruber
Copy link
Author

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.

@joehand
Copy link
Contributor

joehand commented Jan 30, 2018

More information on this hyperdrive issue: holepunchto/hyperdrive#160 and started a PR to fix some of it: holepunchto/hyperdrive#186.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants