Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
fetch-in-chunks
Advanced tools
A utility for fetching large files in chunks with support for parallel downloads and progress tracking.
A utility for fetching large files in chunks with support for parallel downloads, progress tracking, and request abortion.
Install the package using npm:
npm install fetch-in-chunks
import fetchInChunks from 'fetch-in-chunks';
async function fetchInChunks(url, options = {})
chunkSize
(number
, optional): The size of each chunk in bytes. Defaults to
5 MB (5 _ 1024 _ 1024).maxParallelRequests
(number
, optional): The maximum number of parallel
chunk requests. Defaults to 6. progressCallback
(function
, optional): A
callback function that is called with the downloaded bytes and total file
size. signal
(AbortSignal
, optional): An AbortSignal
to allow aborting
the request.url
(string
): The URL of the file to download.chunkSize
(number
, optional): The size of each chunk in bytes. Defaults to
5 MB.maxParallelRequests
(number
, optional): The maximum number of parallel
chunk requests. Defaults to 6.progressCallback
(function
, optional): A callback function that is called
with the downloaded bytes and total file size. signal
(AbortSignal
,
optional): An AbortSignal
to allow aborting the request.Promise<Blob>
: A promise that resolves to a Blob
containing the downloaded
file.import fetchInChunks from 'fetch-in-chunks';
async function downloadFile() {
try {
const blob = await fetchInChunks('https://example.com/largefile.zip');
// Create a download link and trigger the download
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'largefile.zip';
document.body.appendChild(a);
a.click();
URL.revokeObjectURL(url);
} catch (error) {
console.error('Error fetching file:', error);
}
}
downloadFile();
import fetchInChunks from 'fetch-in-chunks';
async function downloadFileWithProgress() {
try {
const blob = await fetchInChunks('https://example.com/largefile.zip', {
progressCallback: (downloaded, total) => {
console.log(`Downloaded ${((downloaded / total) * 100).toFixed(2)}%`);
},
});
// Create a download link and trigger the download
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'largefile.zip';
document.body.appendChild(a);
a.click();
URL.revokeObjectURL(url);
} catch (error) {
console.error('Error fetching file:', error);
}
}
downloadFileWithProgress();
AbortController
import fetchInChunks from 'fetch-in-chunks';
async function downloadFileWithAbort() {
const controller = new AbortController();
const signal = controller.signal;
try {
const blob = await fetchInChunks('https://example.com/largefile.zip', {
signal,
});
// Create a download link and trigger the download
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'largefile.zip';
document.body.appendChild(a);
a.click();
URL.revokeObjectURL(url);
} catch (error) {
if (error.name === 'AbortError') {
console.log('Download aborted');
} else {
console.error('Error fetching file:', error);
}
}
}
// To abort the download at any time
controller.abort();
This project is licensed under the Apache 2.0 License. See the LICENSE
file
for details.
FAQs
A utility for fetching large files in chunks with support for parallel downloads and progress tracking.
The npm package fetch-in-chunks receives a total of 5 weekly downloads. As such, fetch-in-chunks popularity was classified as not popular.
We found that fetch-in-chunks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.