FileService

new FileService(destination, overwrite)

Constructor of FileService

Parameters:
NameTypeDefaultDescription
destination

The root directory for downloads.

overwritefalse

Whether to overwrite existing files.

Author
  • Nur Rony<pro.nmrony@gmail.com> Manages file system operations including directory creation, path resolution, and stream persistence.

Methods

(async) canWrite(url)

Verifies if writing is permitted based on the overwrite flag and existing files.

Parameters:
NameTypeDescription
url

The URL to check against the file system.

Returns:

Returns true if writing should proceed.

(async) getTargetPath(url)

Get the target directory path

Parameters:
NameTypeDescription
url

The URL to transform.

Returns:

The localized file path.

(async) prepareDirectory(url)

Ensures the destination directory exists for a specific URL.

Parameters:
NameTypeDescription
url

The URL of the file to be saved.

Returns:

The prepared absolute target path.

(async) saveStream(webStream, filePath)

Pipes a web-standard ReadableStream to the local file system using stream/promises.

Parameters:
NameTypeDescription
webStream

The source stream from the network.

filePath

The destination path.

Returns:

Resolves when the stream finishes writing.