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

dat.archive.writeFile results in empty file #163

Open
joehand opened this issue Jul 19, 2017 · 2 comments
Open

dat.archive.writeFile results in empty file #163

joehand opened this issue Jul 19, 2017 · 2 comments

Comments

@joehand
Copy link
Collaborator

joehand commented Jul 19, 2017

Writing a file from archive in dat-node results in empty file.

var Dat = require('dat')

var filePath = 'hello.txt'
var fileContent = 'echo 123'

Dat('./test', function (err, dat) {
  if (err) throw err

  dat.archive.writeFile(filePath, fileContent, function (err) {
    if (err) throw err
    console.log('done')
  })
})

However, this works with plain hyperdrive and dat-storage:

var hyperdrive = require('hyperdrive')
var storage = require('dat-storage')

var filePath = 'hello.txt'
var fileContent = 'echo 123'
var archive = hyperdrive(storage('./test'), {latest: true})

archive.writeFile(filePath, fileContent, function (err) {
  if (err) throw err
  console.log('done')
})
@joehand
Copy link
Collaborator Author

joehand commented Jul 20, 2017

@benrogmans you can address this for now by using the indexing option:

var Dat = require('dat')

var filePath = 'hello.txt'
var fileContent = 'echo 123'

Dat('./test', {indexing: false}, function (err, dat) {
  if (err) throw err

  dat.archive.writeFile(filePath, fileContent, function (err) {
    if (err) throw err
    console.log('done')
  })
})

Sorry, this is a bit hacky. Normally in dat-node we import "in-place" (e.g. files are just being scanned, not created). If files aren't imported in place, we set the indexing false. But those assumptions all fail in this case.

I may make false the default since this is definitely unexpected and not user friendly. But we had some unresolved TODOs around the indexing that I need to refresh myself on to see if we can solve more directly.

I thought this would also fix #164 but that seems to be a separate issue.

derhuerst added a commit to derhuerst/build-wikipedia-feed that referenced this issue Aug 7, 2017
jimpick added a commit to jimpick/mpl that referenced this issue Dec 5, 2017
@juliangruber
Copy link
Collaborator

juliangruber commented Jan 26, 2018

found out more about this issue here: dat-ecosystem-archive/dat-storage#7.

With { indexing: true }, not just the files aren't created on disk, a following dat.archive.readFile() also can't read them.

This is a temporary fix for multidat: dat-ecosystem-archive/multidat@11b702b

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

No branches or pull requests

2 participants