| … | … | @@ -18,6 +18,7 @@ const Corestore = require('corestore') |
| 18 | 18 | const Hyperdrive = require('hyperdrive') |
| 19 | 19 | const CorestoreStorage = require('hypercore-storage') |
| 20 | 20 | const { ContentStore, build, stats } = require('../lib/storage.cjs') |
| 21 | const { publishTree } = require('../lib/publish.cjs') |
| 21 | 22 | const { chunk } = await import('../../hyper-overlay/lib/chunker.js') |
| 22 | 23 | |
| 23 | 24 | const USAGE = `vdrive — a Hyperdrive that stores no blob bytes |
| … | … | @@ -109,37 +110,20 @@ async function publish (args) { |
| 109 | 110 | } |
| 110 | 111 | if (names.length === 0) return fail('nothing to publish under ' + src) |
| 111 | 112 | |
| 112 | | const { content, files } = indexTree(src, names) |
| 113 | | const { store, drive } = openDrive(storeDir, content) |
| 114 | | await drive.ready() |
| 113 | // --root anchors the locations index. Successive releases usually live in |
| 114 | // sibling directories under one root; pass it so the index written now still |
| 115 | // resolves the bytes of releases published earlier. |
| 116 | const root = args.flags.root ? path.resolve(args.flags.root) : path.resolve(src) |
| 115 | 117 | |
| 116 | | for (const f of files) { |
| 117 | | // 0-byte + dedup is an upstream crash on read (hyperblobs seekBlockMap) |
| 118 | | const ws = drive.createWriteStream(f.name, f.size === 0 ? {} : { dedup: true }) |
| 119 | | for (const c of f.chunks) await write(ws, c.data) |
| 120 | | await new Promise((resolve, reject) => { |
| 121 | | ws.once('error', reject) |
| 122 | | ws.once('close', resolve) |
| 123 | | ws.end() |
| 124 | | }) |
| 125 | | } |
| 118 | const result = await publishTree({ |
| 119 | storeDir, |
| 120 | root, |
| 121 | chunk, |
| 122 | files: names.map((name) => ({ name, file: path.join(src, name) })) |
| 123 | }) |
| 126 | 124 | |
| 127 | | await drive.getBlobs() |
| 128 | | const result = { |
| 129 | | link: 'pear://' + idEnc.normalize(drive.key), |
| 130 | | key: drive.key.toString('hex'), |
| 131 | | files: files.length, |
| 132 | | bytes: files.reduce((a, f) => a + f.size, 0), |
| 133 | | blocks: drive.blobs.core.length, |
| 134 | | pointerBlocks: stats.putRedirected, |
| 135 | | literalBlocks: stats.putStored |
| 136 | | } |
| 137 | | await drive.close() |
| 138 | | await store.close() |
| 139 | 125 | await compact(storeDir) |
| 140 | | result.driveStoreBytes = du(storeDir) |
| 141 | | content.close() |
| 142 | | return result |
| 126 | return { ...result, driveStoreBytes: du(storeDir) } |
| 143 | 127 | } |
| 144 | 128 | |
| 145 | 129 | async function info (args) { |