Comparing version 3.0.9 to 3.0.10
@@ -46,2 +46,3 @@ import ProgressStatusFile, { DownloadStatus, ProgressStatus } from "./progress-status-file.js"; | ||
protected _downloadStatus: DownloadStatus; | ||
private _latestProgressDate; | ||
constructor(file: DownloadFile, options: DownloadEngineFileOptions); | ||
@@ -48,0 +49,0 @@ get downloadSize(): number; |
@@ -24,2 +24,3 @@ import ProgressStatusFile, { DownloadStatus } from "./progress-status-file.js"; | ||
_downloadStatus = DownloadStatus.Active; | ||
_latestProgressDate = 0; | ||
constructor(file, options) { | ||
@@ -48,5 +49,6 @@ super(); | ||
.reduce((acc, part) => acc + part.size, 0); | ||
const chunksBytes = activeDownloadBytes + previousPartsBytes; | ||
const streamingBytes = Object.values(this._activeStreamBytes) | ||
.reduce((acc, bytes) => acc + bytes, 0); | ||
const partNotFinishedYet = this._progress.part < this.file.parts.length - 1; | ||
const chunksBytes = (partNotFinishedYet ? activeDownloadBytes : 0) + previousPartsBytes; | ||
return Math.min(chunksBytes + streamingBytes, this.downloadSize); | ||
@@ -96,2 +98,5 @@ } | ||
} | ||
// All parts are downloaded, we can clear the progress | ||
this._activeStreamBytes = {}; | ||
this._latestProgressDate = 0; | ||
if (this._closed) | ||
@@ -101,3 +106,2 @@ return; | ||
this._downloadStatus = DownloadStatus.Finished; | ||
await this._saveProgress(); | ||
this.emit("finished"); | ||
@@ -153,6 +157,9 @@ await this.options.onFinishAsync?.(); | ||
_saveProgress() { | ||
const thisProgress = this._latestProgressDate = Date.now(); | ||
this._sendProgressDownloadPart(); | ||
this.emit("save", this._progress); | ||
this._sendProgressDownloadPart(); | ||
return withLock(this, "_saveLock", async () => { | ||
await this.options.onSaveProgressAsync?.(this._progress); | ||
if (thisProgress === this._latestProgressDate) { | ||
await this.options.onSaveProgressAsync?.(this._progress); | ||
} | ||
}); | ||
@@ -159,0 +166,0 @@ } |
import BaseDownloadEngineWriteStream from "./base-download-engine-write-stream.js"; | ||
import WriterIsClosedError from "./errors/writer-is-closed-error.js"; | ||
import WriterNotDefineError from "./errors/writer-not-define-error.js"; | ||
export default class DownloadEngineWriteStreamBrowser extends BaseDownloadEngineWriteStream { | ||
@@ -20,3 +22,3 @@ _writer; | ||
if (!this.options.file) { | ||
throw new Error("Writer & file is not defined, please provide a writer or file"); | ||
throw new WriterNotDefineError("Writer & file is not defined, please provide a writer or file"); | ||
} | ||
@@ -27,3 +29,3 @@ return this._memory = new Uint8Array(this.options.file.totalSize); | ||
if (this.writerClosed) { | ||
throw new Error("Writer is closed"); | ||
throw new WriterIsClosedError(); | ||
} | ||
@@ -30,0 +32,0 @@ if (!this._writer) { |
@@ -10,2 +10,3 @@ import retry from "async-retry"; | ||
private _fd; | ||
private _fileWriteFinished; | ||
readonly options: DownloadEngineWriteStreamOptionsNodeJS; | ||
@@ -12,0 +13,0 @@ fileSize: number; |
@@ -6,2 +6,3 @@ import fs from "fs/promises"; | ||
import BaseDownloadEngineWriteStream from "./base-download-engine-write-stream.js"; | ||
import WriterIsClosedError from "./errors/writer-is-closed-error.js"; | ||
const DEFAULT_OPTIONS = { | ||
@@ -13,2 +14,3 @@ mode: "r+" | ||
_fd = null; | ||
_fileWriteFinished = false; | ||
options; | ||
@@ -38,2 +40,3 @@ fileSize = 0; | ||
async ftruncate(size = this.fileSize) { | ||
this._fileWriteFinished = true; | ||
await retry(async () => { | ||
@@ -45,2 +48,5 @@ const fd = await this._ensureFileOpen(); | ||
async saveMedataAfterFile(data) { | ||
if (this._fileWriteFinished) { | ||
throw new WriterIsClosedError(); | ||
} | ||
const jsonString = JSON.stringify(data); | ||
@@ -47,0 +53,0 @@ const encoder = new TextEncoder(); |
{ | ||
"name": "ipull", | ||
"version": "3.0.9", | ||
"version": "3.0.10", | ||
"description": "The only file downloader you'll ever need. For node.js and the browser, CLI and library for fast and reliable file downloads.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
239928
186
3203