diginext-utils
Version:
README.md
29 lines • 791 B
JavaScript
const fs = require("fs");
/**
* Move file to another location.
*/
export function fileMove(oldPath, newPath, callback) {
fs.rename(oldPath, newPath, function (err) {
if (err) {
if (err.code === "EXDEV") {
copy();
}
else {
callback(err);
}
return;
}
callback();
});
function copy() {
var readStream = fs.createReadStream(oldPath);
var writeStream = fs.createWriteStream(newPath);
readStream.on("error", callback);
writeStream.on("error", callback);
readStream.on("close", function () {
fs.unlink(oldPath, callback);
});
readStream.pipe(writeStream);
}
}
//# sourceMappingURL=fileMove.js.map