« get me outta code hell

Use util.promisify instead of mz/fs - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/play.js
diff options
context:
space:
mode:
authorLiam <towerofnix@gmail.com>2017-05-31 14:17:53 -0300
committerLiam <towerofnix@gmail.com>2017-05-31 14:17:57 -0300
commitf5879e2eb3c86057f6f4a9e477c28ba8edf3824d (patch)
tree0e305d57355d98e7e80aeea391e2ad6c9d6dff72 /play.js
parentd1bf9f5e95f4306bd53b072bd62de98e6e5e3c58 (diff)
Use util.promisify instead of mz/fs
One day I go from the deprecated fs-promise module to the mz/fs
module, the next day Node.js v8.0.0 is released with the new
util.promisify function.. Must I change to a new technology
literally every day? :)
Diffstat (limited to 'play.js')
-rw-r--r--play.js15
1 files changed, 10 insertions, 5 deletions
diff --git a/play.js b/play.js
index badfcf4..8833c89 100644
--- a/play.js
+++ b/play.js
@@ -66,10 +66,15 @@
 
 'use strict'
 
-const fs = require('mz/fs')
+const fs = require('fs')
+const util = require('util')
+const { spawn } = require('child_process')
+
 const fetch = require('node-fetch')
 const sanitize = require('sanitize-filename')
-const { spawn } = require('child_process')
+
+const writeFile = util.promisify(fs.writeFile)
+const readFile = util.promisify(fs.readFile)
 
 function promisifyProcess(proc, showLogging = true) {
 	return new Promise((resolve, reject) => {
@@ -152,7 +157,7 @@ async function loopPlay(fn) {
 
 		const res = await fetch(href)
 		const buffer = await res.buffer()
-		await fs.writeFile('./.temp-track', buffer)
+		await writeFile('./.temp-track', buffer)
 
 		try {
 			await convert('./.temp-track', wavFile)
@@ -301,7 +306,7 @@ async function processArgv(argv, handlers) {
 	}
 }
 
-fs.readFile('./playlist.json', 'utf-8')
+readFile('./playlist.json', 'utf-8')
 	.then(plText => JSON.parse(plText))
 	.then(async playlist => {
 		let sourcePlaylist = playlist
@@ -321,7 +326,7 @@ fs.readFile('./playlist.json', 'utf-8')
 				// Opens a separate playlist file.
 				// This sets the source playlist.
 
-				const openedPlaylist = JSON.parse(await fs.readFile(util.nextArg(), 'utf-8'))
+				const openedPlaylist = JSON.parse(await readFile(util.nextArg(), 'utf-8'))
 				sourcePlaylist = openedPlaylist
 				curPlaylist = openedPlaylist
 			},