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

dat.archive.writeFile results in empty file #163

Open

Description

@joehand

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')
})

Activity

  1. joehand commented on Jul 20, 2017

    @joehand
    CollaboratorAuthor

    @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.

  2. juliangruber commented on Jan 26, 2018

    @juliangruber
    Collaborator

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions