Skip to content

Commit

Permalink
Change how local state of the file is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
MKPLKN committed Sep 3, 2024
1 parent b5721c1 commit 5e17e15
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ module.exports = class Monitor extends ReadyResource {
this.entry = await this.drive.entry(this.name)
if (this.entry) this._setEntryInfo()

// load the local state for the file.
// upload is a bit more tricky
// load the local state of the file.
// upload is a bit more tricky...
if (this.entry && this.isDownload) {
await this._loadLocalState().catch(safetyCatch).finally(() => {
this._calculateStats()
Expand Down Expand Up @@ -81,11 +81,15 @@ module.exports = class Monitor extends ReadyResource {
}

async _loadLocalState () {
// TODO: think this will only work if its linear
const stream = this.blobs.createReadStream(this.entry.value.blob, { wait: false })
for await (const bytes of stream) {
this.stats.totalBytes += bytes.length
this.stats.blocks++
// @TODO: There's a better way to do this?
let blockIdx = this.stats.blockOffset
while (blockIdx <= this.stats.targetBlocks) {
if (await this.blobs.core.core.bitfield.get(blockIdx)) {
const bytes = await this.blobs.core.core.blocks.get(blockIdx)
this.stats.totalBytes += bytes.length
this.stats.blocks++
}
blockIdx++
}
}

Expand Down

0 comments on commit 5e17e15

Please sign in to comment.