new FileService(destination, overwrite)
Constructor of FileService
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
destination | The root directory for downloads. | ||
overwrite | false | Whether to overwrite existing files. |
- Source
Methods
(async) canWrite(url)
Verifies if writing is permitted based on the overwrite flag and existing files.
Parameters:
| Name | Type | Description |
|---|---|---|
url | The URL to check against the file system. |
- Source
Returns:
Returns true if writing should proceed.
(async) getTargetPath(url)
Get the target directory path
Parameters:
| Name | Type | Description |
|---|---|---|
url | The URL to transform. |
- Source
Returns:
The localized file path.
(async) prepareDirectory(url)
Ensures the destination directory exists for a specific URL.
Parameters:
| Name | Type | Description |
|---|---|---|
url | The URL of the file to be saved. |
- Source
Returns:
The prepared absolute target path.
(async) saveStream(webStream, filePath)
Pipes a web-standard ReadableStream to the local file system using stream/promises.
Parameters:
| Name | Type | Description |
|---|---|---|
webStream | The source stream from the network. | |
filePath | The destination path. |
- Source
Returns:
Resolves when the stream finishes writing.
