Skip to content

Instantly share code, notes, and snippets.

@blahah
Last active May 19, 2017 13:08
Show Gist options
  • Save blahah/287c63db841388ca54b24ebb278591f5 to your computer and use it in GitHub Desktop.
Save blahah/287c63db841388ca54b24ebb278591f5 to your computer and use it in GitHub Desktop.
Recreate EBADF error on windows when syncing files from a hyperdrive
npm init -y
npm install mkdirp blahah/hyperdrive dat-storage folder-walker through2 hyperdiscovery pumpify untildify
const path = require('path')
const untildify = require('untildify')
const mkdirp = require('mkdirp').sync
const hyperdrive = require('hyperdrive')
const discover = require('hyperdiscovery')
const storage = require('dat-storage')
const walker = require('folder-walker')
const through = require('through2')
const pumpify = require('pumpify')
const key = 'ce62c46f51f1e50fbf9da718540003b47ffce5f19279162ce975a7d0aca164de'
const dataroot = untildify('~/.sciencefair')
const datadir = path.join(dataroot, 'datasources', key)
const jsondir = path.join(datadir, 'meta_feed')
mkdirp(datadir)
const archive = hyperdrive(storage(jsondir), key, {
latest: true,
sparse: false,
live: false
})
archive.once('ready', () => discover(archive, { tcp: true, utp: true }))
const getentry = through.ctor({ objectMode: true }, (data, enc, next) => {
archive.readFile(data.filepath, 'utf8', (err, json) => {
if (err) throw err
else {
console.log(json)
next()
}
})
})
pumpify.obj(
walker('/meta', { fs: archive }),
getentry()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment