mirror of
https://github.com/Foltik/Shimapan
synced 2024-11-10 23:53:31 -05:00
28 lines
760 B
JavaScript
28 lines
760 B
JavaScript
const fs = require('fs');
|
|
const fsPromises = fs.promises;
|
|
|
|
const mkdir = path => new Promise((resolve, reject) => {
|
|
fsPromises.mkdir(path)
|
|
.then(resolve)
|
|
.catch(err => {
|
|
if (err.code === 'EEXIST')
|
|
resolve();
|
|
else
|
|
reject(err);
|
|
});
|
|
});
|
|
|
|
const write = (path, stream) => new Promise((resolve, reject) => {
|
|
const outStream = fs.createWriteStream(path);
|
|
stream.pipe(outStream);
|
|
outStream.on('error', reject);
|
|
outStream.on('close', () => resolve(outStream.bytesWritten));
|
|
outStream.on('finish', () => resolve(outStream.bytesWritten));
|
|
});
|
|
|
|
const remove = path =>
|
|
fsPromises.unlink(path);
|
|
|
|
exports.mkdir = mkdir;
|
|
exports.write = write;
|
|
exports.remove = remove; |