Question
How do you asynchronously download and (resumable/multi-part) upload large MP4 files purely through Streams in NodeJS (without using filesystem)?
Scenario
I'm writing a class file that is concerned with streaming downloads from a URL to Google Drive or Dropbox purely through memory.
**The file size is known prior to the download and upload.
Visual
==============
^(5%) ^(10%)
Downloader
==============
^(5%) ^(10%)
Uploader
Requirements
- Transfer through Memory Streams (without storing anything on the filesystem)
- The uploads should be multi-part resumable and may range anywhere from 5 Mb to > 20 Gb.
- If a download or upload fails, there should be a set number of retries.
Curiosities
- Is a duplex stream (e.g. passthrough) the correct way of doing this?
- How do you convey
Content-Lengthwithin an asynchronous method as visualized above?
Pseudo Code
const axios = require('axios');
const stream = require('stream');
const passtrough = new stream.PassThrough();
let sample = VideoAPI.get() // pass id
//sample.url // url located here
//sample.size // size is known prior to download or upload
//sample.contentType // content-type is known prior to download
//Download sample via Axios
axios.get(sample.url, {
responseType: "stream"
}).then((response) => {
//TODO: Pipe to Google Drive
console.log('response', response)
}).catch((error) => {
console.error(error)
})
Research