dat-ecosystem-archive / dat-node

Node module for creating dat compatible tools on file systems [ DEPRECATED - More info on active projects and modules at https://dat-ecosystem.org/ ]
https://dat.foundation
MIT License
501 stars 63 forks source link

DAT version discrepancies #224

Open martinheidegger opened 5 years ago

martinheidegger commented 5 years ago

(note: I am not sure if this is an issue of hyperdrive or dat-node, following @karissa 's suggestion to post it here - thanks @karissa )

I am reporting a bug or unexpected behavior:

The version of a newly created DAT when .ready is called persists at 0, even if a dedicated version is specified.

Bug Report

Expected behavior

I am expecting the following code to properly list the version & files of that version.

const createDat = require('dat-node')

createDat(`${__dirname}/download`, {
  key: 'dat://56ff8bae4339defdb4bbe4e18d3fb5c17806429d59ce2e775b7832501c8781d1/',
  version: 11,
  temp: true
}, function (err, dat) {
  if (err) throw err

  dat.joinNetwork()

  dat.archive.ready(function () {
    console.log(`Version on ready: ${dat.archive.version}`)
  })

  dat.archive.readdir('/', function (err, list) {
    if (err) throw err
    console.log(`Version on list: ${dat.archive.version}`)
    console.log(list)
  })
})

to have following output

Version on ready: 11
Version on list: 11
[ 'LICENSE', 'README.md', 'images', 'dat.json', 'index.html' ]

Actual behavior

Version on ready: 0
Version on list: 11
[ 'LICENSE', 'README.md', 'images', 'dat.json', 'index.html' ]
joehand commented 5 years ago

Ya, I've seen this before.

I think this happens when metadata isn't downloaded, returning a length of 0. But when I saw it before, it wasn't clear if that was a bug or something we should expect to happen.