Skip to content

Instantly share code, notes, and snippets.

@HDegroote
Created October 10, 2025 10:11
Show Gist options
  • Select an option

  • Save HDegroote/b6e216732708bc1ce563b3e4ef13c21b to your computer and use it in GitHub Desktop.

Select an option

Save HDegroote/b6e216732708bc1ce563b3e4ef13c21b to your computer and use it in GitHub Desktop.
Creat drive with dummy files
const Corestore = require('corestore')
const Hyperdrive = require('hyperdrive')
const Hyperswarm = require('hyperswarm')
const byteSize = require('tiny-byte-size')
const IdEnc = require('hypercore-id-encoding')
async function main () {
const store = new Corestore('drive-create-store')
const drive = new Hyperdrive(store.namespace('drive'))
await drive.ready()
const swarm = new Hyperswarm()
swarm.on('connection', conn => {
store.replicate(conn)
conn.on('error', (e) => {
console.log(`Connection error: ${e.stack}`)
})
})
const maxFileSize = 2 ** 31
console.log(`Creating files of doubling length up to ${maxFileSize}`)
for (let size = 1; size <= maxFileSize; size *= 2) {
const byteStr = byteSize(size)
if (await drive.exists(byteStr)) continue
console.log(`putting file of ${byteStr}`)
await drive.put(byteStr, Buffer.allocUnsafe(size))
}
swarm.join(drive.discoveryKey)
console.log(`Swarming drive with pub key ${IdEnc.normalize(drive.key)}`)
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment