-
Notifications
You must be signed in to change notification settings - Fork 431
Description
My video hls data is stored at my MEGA account and MEGA provides an api that can be used to stream the download of that data. The function exposes the actual buffer data that is being downloaded. Below is a snippet of how it works
file.download((err, data) => {
// data is buffer
})This function downloads files using chunked multiple parallel connections to speed up downloading. Similar to the MEGA implementation it first loads a 128KB chunk, then a 256KB, increasing it until it reaches 1MB. You can use the options below to control that.
maxConnections: the number of parallel connections is defined (default: 4);
initialChunkSize: first chunk size, in bytes (default: 128KB);
chunkSizeIncrement: how many bytes to increment each time (default: 128KB);
maxChunkSize: maximum chunk size, in bytes (max 1MB);
returnCiphertext: if true the ciphertext will be returned, which can be decrypted later using decrypt low level function.
handleRetries: accepts a function to handle retries on chunk downloading errors, overrides the function defined by File.defaultHandleRetries;
forceHttps: if set to true will download using HTTPS, if set to false will download using HTTP. Default to false in the Node build and true in the browser build or if a Deno global is set.
The download function also support start and end options, like fs.createReadStream.