@qvac/registry-client 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +42 -2
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -247,11 +247,21 @@ class QVACRegistryClient extends ReadyResource {
|
|
|
247
247
|
|
|
248
248
|
const totalSize = model.blobBinding.byteLength
|
|
249
249
|
|
|
250
|
+
const rangeDownload = core.download({
|
|
251
|
+
start: model.blobBinding.blockOffset,
|
|
252
|
+
length: model.blobBinding.blockLength
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
const blockStart = model.blobBinding.blockOffset
|
|
256
|
+
const blockEnd = blockStart + model.blobBinding.blockLength
|
|
257
|
+
|
|
250
258
|
let artifact
|
|
251
259
|
if (options.outputFile) {
|
|
252
260
|
await this._streamBlobToFile(blobs, core, model.blobBinding, options.outputFile, options)
|
|
253
261
|
artifact = { path: options.outputFile, totalSize }
|
|
254
262
|
|
|
263
|
+
rangeDownload.destroy()
|
|
264
|
+
await this._clearBlobBlocks(core, blockStart, blockEnd)
|
|
255
265
|
if (blobs) await blobs.close()
|
|
256
266
|
if (core) await core.close()
|
|
257
267
|
} else {
|
|
@@ -262,6 +272,8 @@ class QVACRegistryClient extends ReadyResource {
|
|
|
262
272
|
artifact = { stream, totalSize }
|
|
263
273
|
|
|
264
274
|
const cleanup = async () => {
|
|
275
|
+
rangeDownload.destroy()
|
|
276
|
+
await this._clearBlobBlocks(core, blockStart, blockEnd)
|
|
265
277
|
if (blobs) {
|
|
266
278
|
try {
|
|
267
279
|
await blobs.close()
|
|
@@ -279,7 +291,7 @@ class QVACRegistryClient extends ReadyResource {
|
|
|
279
291
|
this.logger.debug('Blob resources closed after stream end')
|
|
280
292
|
}
|
|
281
293
|
|
|
282
|
-
stream.
|
|
294
|
+
stream.once('end', cleanup)
|
|
283
295
|
}
|
|
284
296
|
|
|
285
297
|
this.logger.info('Model downloaded successfully')
|
|
@@ -359,11 +371,21 @@ class QVACRegistryClient extends ReadyResource {
|
|
|
359
371
|
}
|
|
360
372
|
const totalSize = blobBinding.byteLength
|
|
361
373
|
|
|
374
|
+
const blockStart = pointer.blockOffset
|
|
375
|
+
const blockEnd = blockStart + pointer.blockLength
|
|
376
|
+
|
|
377
|
+
const rangeDownload = core.download({
|
|
378
|
+
start: pointer.blockOffset,
|
|
379
|
+
length: pointer.blockLength
|
|
380
|
+
})
|
|
381
|
+
|
|
362
382
|
let artifact
|
|
363
383
|
if (options.outputFile) {
|
|
364
384
|
await this._streamBlobToFile(blobs, core, pointer, options.outputFile, options)
|
|
365
385
|
artifact = { path: options.outputFile, totalSize }
|
|
366
386
|
|
|
387
|
+
rangeDownload.destroy()
|
|
388
|
+
await this._clearBlobBlocks(core, blockStart, blockEnd)
|
|
367
389
|
if (blobs) await blobs.close()
|
|
368
390
|
if (core) await core.close()
|
|
369
391
|
} else {
|
|
@@ -374,6 +396,8 @@ class QVACRegistryClient extends ReadyResource {
|
|
|
374
396
|
artifact = { stream, totalSize }
|
|
375
397
|
|
|
376
398
|
const cleanup = async () => {
|
|
399
|
+
rangeDownload.destroy()
|
|
400
|
+
await this._clearBlobBlocks(core, blockStart, blockEnd)
|
|
377
401
|
if (blobs) {
|
|
378
402
|
try { await blobs.close() } catch (e) {
|
|
379
403
|
this.logger.warn('Error closing blob instance', { error: e.message })
|
|
@@ -387,7 +411,7 @@ class QVACRegistryClient extends ReadyResource {
|
|
|
387
411
|
this.logger.debug('Blob resources closed after stream end')
|
|
388
412
|
}
|
|
389
413
|
|
|
390
|
-
stream.
|
|
414
|
+
stream.once('end', cleanup)
|
|
391
415
|
}
|
|
392
416
|
|
|
393
417
|
this.logger.info('Blob download complete (direct)')
|
|
@@ -411,6 +435,16 @@ class QVACRegistryClient extends ReadyResource {
|
|
|
411
435
|
}
|
|
412
436
|
}
|
|
413
437
|
|
|
438
|
+
async _clearBlobBlocks (core, start, end) {
|
|
439
|
+
try {
|
|
440
|
+
const cleared = await core.clear(start, end, { diff: true })
|
|
441
|
+
await core.compact()
|
|
442
|
+
this.logger.info('Cleared blob blocks from corestore', { start, end, blocks: cleared ? cleared.blocks : end - start })
|
|
443
|
+
} catch (err) {
|
|
444
|
+
this.logger.warn('Failed to clear blob blocks from corestore', { error: err.message })
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
414
448
|
async _streamBlobToFile (blobs, core, blobPointer, filePath, options) {
|
|
415
449
|
const { cachedBlocks, totalBlocks, totalBytes } = await this._checkBlobProgress(core, blobPointer)
|
|
416
450
|
|
|
@@ -450,6 +484,11 @@ class QVACRegistryClient extends ReadyResource {
|
|
|
450
484
|
|
|
451
485
|
core.on('download', progressHandler)
|
|
452
486
|
|
|
487
|
+
const rangeDownload = core.download({
|
|
488
|
+
start: blobPointer.blockOffset,
|
|
489
|
+
length: blobPointer.blockLength
|
|
490
|
+
})
|
|
491
|
+
|
|
453
492
|
const stream = blobs.createReadStream(blobPointer, {
|
|
454
493
|
wait: true,
|
|
455
494
|
timeout: options.timeout || 30000
|
|
@@ -482,6 +521,7 @@ class QVACRegistryClient extends ReadyResource {
|
|
|
482
521
|
}
|
|
483
522
|
})
|
|
484
523
|
} finally {
|
|
524
|
+
rangeDownload.destroy()
|
|
485
525
|
core.off('download', progressHandler)
|
|
486
526
|
}
|
|
487
527
|
}
|