Skip to content

Commit

Permalink
Merge pull request #13 from Jonahss/fs-extra
Browse files Browse the repository at this point in the history
upgrade fs-extra and remove fs-promise
  • Loading branch information
evertonfraga committed May 25, 2018
2 parents 47f9617 + 60acf58 commit 4954ed0
Show file tree
Hide file tree
Showing 4 changed files with 2,317 additions and 943 deletions.
21 changes: 10 additions & 11 deletions lib/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
var Q = require("bluebird");
var assert = require("assert");
var crypto = require("crypto");
var fs = require("fs");
var fsp = require("fs-promise");
var fs = require("fs-extra");
var got = require("got");
var mkdirp = require("mkdirp-promise");
var path = require("path");
Expand Down Expand Up @@ -102,13 +101,13 @@ var extract = function extract(fromPath) {
// Reads a file as an UTF8 string.
// Returns a promise containing that string.
var readUTF8 = function readUTF8(path) {
return fsp.readFile(path, { encoding: "utf8" });
return fs.readFile(path, { encoding: "utf8" });
};

// String ~> Promise Bool
var isDirectory = function isDirectory(path) {
return fsp.exists(path).then(assert).then(function () {
return fsp.lstat(path);
return fs.exists(path).then(assert).then(function () {
return fs.lstat(path);
}).then(function (stats) {
return stats.isDirectory();
}).catch(function () {
Expand All @@ -125,7 +124,7 @@ var directoryTree = function directoryTree(dirPath) {
var searchOnDir = function searchOnDir(dir) {
return search(path.join(dirPath, dir));
};
return Q.all(Q.map(fsp.readdir(dirPath), searchOnDir));
return Q.all(Q.map(fs.readdir(dirPath), searchOnDir));
} else {
paths.push(dirPath);
};
Expand Down Expand Up @@ -165,8 +164,8 @@ var safeDownloadArchived = function safeDownloadArchived(url) {
}).then(function () {
return filePath;
}).catch(function () {
return fsp.exists(archiveDir).then(function (exists) {
return !exists ? fsp.mkdir(archiveDir) : null;
return fs.exists(archiveDir).then(function (exists) {
return !exists ? fs.mkdir(archiveDir) : null;
}).then(function () {
return download(url)(archivePath).onData(promise.onDataCallback);
}).then(function () {
Expand All @@ -178,9 +177,9 @@ var safeDownloadArchived = function safeDownloadArchived(url) {
}).then(function () {
return search(new RegExp(fileName + "$"))(archiveDir);
}).then(function (fp) {
return fsp.rename(fp[0], filePath);
return fs.rename(fp[0], filePath);
}).then(function () {
return fsp.unlink(archivePath);
return fs.unlink(archivePath);
}).then(function () {
return fileHash ? checksum(fileHash)(filePath) : null;
}).then(function () {
Expand Down Expand Up @@ -248,4 +247,4 @@ module.exports = {
downloadArchived: downloadArchived,
search: search,
test: test
};
};
Loading

0 comments on commit 4954ed0

Please sign in to comment.