Skip to content

Instantly share code, notes, and snippets.

@joehand
Created March 15, 2019 17:58
Show Gist options
  • Save joehand/ad9d3a3dc7f7d7ab611307d396025fbe to your computer and use it in GitHub Desktop.
Save joehand/ad9d3a3dc7f7d7ab611307d396025fbe to your computer and use it in GitHub Desktop.
var hyperdrive = require('hyperdrive')
var pump = require('pump')
var fs = require('fs')
var storage = require('dat-storage')
var source = hyperdrive('./source')
source.ready(() => {
var dest = hyperdrive(storage('./dest'), source.key, {
latest: true, sparse: false
})
dest.on('syncing', () => {
console.log('dest syncing')
console.log(' dest version:', dest.version)
console.log(' source version:', source.version)
})
dest.on('sync', () => {
console.log('dest sync, version:', dest.version)
})
setInterval(() => {
source.readFile('hi.txt', 'utf8', (err,data) => {
if (!data) data = ''
source.writeFile('hi.txt', data + new Date() + '\n')
})
}, 1000)
var stream = dest.replicate({live: true})
stream.pipe(source.replicate()).pipe(stream)
})
{
"name": "latest-cpu",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dat-storage": "^1.1.1",
"hyperdrive": "^9.14.2",
"pump": "^3.0.0"
}
}
@joehand
Copy link
Author

joehand commented Mar 15, 2019

Hmmm @jedahan I still saw the same bug with node v10.

@joehand
Copy link
Author

joehand commented Mar 15, 2019

@allain, ya seems this is happening whenever latest: true regardless of storage.

@allain
Copy link

allain commented Mar 16, 2019

_fetchVersion callback is called multiple times https://github.com/mafintosh/hyperdrive/blob/acf7d5416d4a189170a13073012176b5c5c4c0cd/index.js#L184

That should help narrow down the bug.

It happens on node v9, v10, and v11 for me.

@jedahan
Copy link

jedahan commented Mar 16, 2019

@joehand @allain sorry, I meant node 11, but the v10 branch of hyperdrive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment