« get me outta code hell

http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/downloaders.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/downloaders.js')
-rw-r--r--src/downloaders.js19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/downloaders.js b/src/downloaders.js
index 527f67d..3f3a427 100644
--- a/src/downloaders.js
+++ b/src/downloaders.js
@@ -33,4 +33,21 @@ function makeYouTubeDownloader() {
   }
 }
 
-module.exports = {makeHTTPDownloader, makeYouTubeDownloader}
+function makeLocalDownloader() {
+  return function(arg, out) {
+    const read = fs.createReadStream(arg)
+    const write = fs.createWriteStream(out)
+
+    return new Promise((resolve, reject) => {
+      write.on('error', err => reject(err))
+      write.on('close', () => resolve())
+      read.pipe(write)
+    })
+  }
+}
+
+module.exports = {
+  makeHTTPDownloader,
+  makeYouTubeDownloader,
+  makeLocalDownloader
+}