Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
121 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// This is adapted from https://github.com/normalize/mz | ||
// Copyright (c) 2014-2016 Jonathan Ong me@jongleberry.com and Contributors | ||
|
||
/* eslint-env mocha */ | ||
const assert = require('assert') | ||
const fs = require('../..') | ||
|
||
describe('fs', () => { | ||
it('.stat()', done => { | ||
fs.stat(__filename).then(function (stats) { | ||
assert.equal(typeof stats.size, 'number') | ||
done() | ||
}).catch(done) | ||
}) | ||
|
||
it('.statSync()', () => { | ||
const stats = fs.statSync(__filename) | ||
assert.equal(typeof stats.size, 'number') | ||
}) | ||
|
||
it('.exists()', done => { | ||
fs.exists(__filename).then(function (exists) { | ||
assert(exists) | ||
done() | ||
}).catch(done) | ||
}) | ||
|
||
it('.existsSync()', () => { | ||
const exists = fs.existsSync(__filename) | ||
assert(exists) | ||
}) | ||
|
||
describe('callback support', () => { | ||
it('.stat()', done => { | ||
fs.stat(__filename, function (err, stats) { | ||
assert(!err) | ||
assert.equal(typeof stats.size, 'number') | ||
done() | ||
}) | ||
}) | ||
|
||
// This test is different from mz/fs, since we are a drop-in replacement for native fs | ||
it('.exists()', done => { | ||
fs.exists(__filename, function (exists) { | ||
assert(exists) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// This is adapted from https://github.com/normalize/mz | ||
// Copyright (c) 2014-2016 Jonathan Ong me@jongleberry.com and Contributors | ||
const u = require('universalify').fromCallback | ||
const fs = require('graceful-fs') | ||
|
||
const api = [ | ||
'rename', | ||
'ftruncate', | ||
'chown', | ||
'fchown', | ||
'lchown', | ||
'chmod', | ||
'fchmod', | ||
'stat', | ||
'lstat', | ||
'fstat', | ||
'link', | ||
'symlink', | ||
'readlink', | ||
'realpath', | ||
'unlink', | ||
'rmdir', | ||
'mkdir', | ||
'readdir', | ||
'close', | ||
'open', | ||
'utimes', | ||
'futimes', | ||
'fsync', | ||
'fdatasync', | ||
'write', | ||
'read', | ||
'readFile', | ||
'writeFile', | ||
'appendFile', | ||
'truncate' | ||
] | ||
// fs.mkdtemp() was added in Node.js v5.10.0, so check if it exists | ||
typeof fs.mkdtemp === 'function' && api.push('mkdtemp') | ||
|
||
// Export all keys: | ||
Object.keys(fs).forEach(key => { | ||
exports[key] = fs[key] | ||
}) | ||
|
||
// Universalify async methods: | ||
api.forEach(method => { | ||
exports[method] = u(fs[method]) | ||
}) | ||
|
||
// We differ from mz/fs in that we still ship the old, broken, fs.exists() | ||
// since we are a drop-in replacement for the native module | ||
exports.exists = function (filename, callback) { | ||
if (typeof callback === 'function') { | ||
return fs.exists(filename, function (exists) { | ||
callback(exists) | ||
}) | ||
} | ||
return new Promise(function (resolve) { | ||
return fs.exists(filename, function (exists) { | ||
resolve(exists) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters