From f5879e2eb3c86057f6f4a9e477c28ba8edf3824d Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 31 May 2017 14:17:53 -0300 Subject: 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? :) --- play.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'play.js') 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 }, -- cgit 1.3.0-6-gf8a5