@bevry/file
Advanced tools
Comparing version 1.0.0 to 1.1.0-next.1627579665.0514159d2989aa4e4e73620236db70ce6c1d0058
@@ -31,2 +31,6 @@ /** Check access of a file */ | ||
export declare function deleteFile(path: string): Promise<void>; | ||
/** Read a directory */ | ||
export declare function readdir(path: string): Promise<Array<string>>; | ||
/** Read a directory safely */ | ||
export declare function readDirectory(path: string): Promise<Array<string>>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { access as _access, readFile as _readFile, writeFile as _writeFile, unlink as _unlink, constants, } from 'fs'; | ||
import { access as _access, readFile as _readFile, writeFile as _writeFile, unlink as _unlink, readdir as _readdir, constants, } from 'fs'; | ||
import Errlop from 'errlop'; | ||
@@ -162,1 +162,35 @@ /** Check access of a file */ | ||
} | ||
/** Read a directory */ | ||
export function readdir(path) { | ||
return new Promise(function (resolve, reject) { | ||
_readdir(path, function (err, files) { | ||
if (err) | ||
return reject(new Errlop(`failed to read file at: ${path}`, err)); | ||
return resolve(files); | ||
}); | ||
}); | ||
} | ||
/** Read a directory safely */ | ||
export async function readDirectory(path) { | ||
// check exists | ||
try { | ||
await exists(path); | ||
} | ||
catch (err) { | ||
throw new Errlop(`unable to read the non-existent directory: ${path}`, err); | ||
} | ||
// check readable | ||
try { | ||
await readable(path); | ||
} | ||
catch (err) { | ||
throw new Errlop(`no read permission for the directory: ${path}`, err); | ||
} | ||
// attempt read | ||
try { | ||
return await readdir(path); | ||
} | ||
catch (err) { | ||
throw new Errlop(`failed to read the existing and readable directory: ${path}`, err); | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { access as _access, readFile as _readFile, writeFile as _writeFile, unlink as _unlink, constants, } from 'fs'; | ||
import { access as _access, readFile as _readFile, writeFile as _writeFile, unlink as _unlink, readdir as _readdir, constants, } from 'fs'; | ||
import Errlop from 'errlop'; | ||
@@ -162,1 +162,35 @@ /** Check access of a file */ | ||
} | ||
/** Read a directory */ | ||
export function readdir(path) { | ||
return new Promise(function (resolve, reject) { | ||
_readdir(path, function (err, files) { | ||
if (err) | ||
return reject(new Errlop(`failed to read file at: ${path}`, err)); | ||
return resolve(files); | ||
}); | ||
}); | ||
} | ||
/** Read a directory safely */ | ||
export async function readDirectory(path) { | ||
// check exists | ||
try { | ||
await exists(path); | ||
} | ||
catch (err) { | ||
throw new Errlop(`unable to read the non-existent directory: ${path}`, err); | ||
} | ||
// check readable | ||
try { | ||
await readable(path); | ||
} | ||
catch (err) { | ||
throw new Errlop(`no read permission for the directory: ${path}`, err); | ||
} | ||
// attempt read | ||
try { | ||
return await readdir(path); | ||
} | ||
catch (err) { | ||
throw new Errlop(`failed to read the existing and readable directory: ${path}`, err); | ||
} | ||
} |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.deleteFile = exports.unlink = exports.writeFile = exports.write = exports.readFile = exports.read = exports.isExecutable = exports.executable = exports.isWritable = exports.writable = exports.isReadable = exports.readable = exports.isPresent = exports.exists = exports.access = void 0; | ||
exports.readDirectory = exports.readdir = exports.deleteFile = exports.unlink = exports.writeFile = exports.write = exports.readFile = exports.read = exports.isExecutable = exports.executable = exports.isWritable = exports.writable = exports.isReadable = exports.readable = exports.isPresent = exports.exists = exports.access = void 0; | ||
const fs_1 = require("fs"); | ||
@@ -184,1 +184,37 @@ const errlop_1 = __importDefault(require("errlop")); | ||
exports.deleteFile = deleteFile; | ||
/** Read a directory */ | ||
function readdir(path) { | ||
return new Promise(function (resolve, reject) { | ||
fs_1.readdir(path, function (err, files) { | ||
if (err) | ||
return reject(new errlop_1.default(`failed to read file at: ${path}`, err)); | ||
return resolve(files); | ||
}); | ||
}); | ||
} | ||
exports.readdir = readdir; | ||
/** Read a directory safely */ | ||
async function readDirectory(path) { | ||
// check exists | ||
try { | ||
await exists(path); | ||
} | ||
catch (err) { | ||
throw new errlop_1.default(`unable to read the non-existent directory: ${path}`, err); | ||
} | ||
// check readable | ||
try { | ||
await readable(path); | ||
} | ||
catch (err) { | ||
throw new errlop_1.default(`no read permission for the directory: ${path}`, err); | ||
} | ||
// attempt read | ||
try { | ||
return await readdir(path); | ||
} | ||
catch (err) { | ||
throw new errlop_1.default(`failed to read the existing and readable directory: ${path}`, err); | ||
} | ||
} | ||
exports.readDirectory = readDirectory; |
# History | ||
## v1.1.0 2021 July 30 | ||
- Add `readDirectory` | ||
## v1.0.0 2021 July 30 | ||
- Initial working release |
{ | ||
"name": "@bevry/file", | ||
"version": "1.0.0", | ||
"version": "1.1.0-next.1627579665.0514159d2989aa4e4e73620236db70ce6c1d0058", | ||
"description": "Helpers for reading, writing, deleting, and accessing a file.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/bevry/file", |
@@ -55,3 +55,3 @@ <!-- TITLE/ --> | ||
<script type="module"> | ||
import * as pkg from '//cdn.skypack.dev/@bevry/file@^1.0.0' | ||
import * as pkg from '//cdn.skypack.dev/@bevry/file@^1.1.0' | ||
</script> | ||
@@ -64,3 +64,3 @@ ``` | ||
<script type="module"> | ||
import * as pkg from '//unpkg.com/@bevry/file@^1.0.0' | ||
import * as pkg from '//unpkg.com/@bevry/file@^1.1.0' | ||
</script> | ||
@@ -73,3 +73,3 @@ ``` | ||
<script type="module"> | ||
import * as pkg from '//dev.jspm.io/@bevry/file@1.0.0' | ||
import * as pkg from '//dev.jspm.io/@bevry/file@1.1.0' | ||
</script> | ||
@@ -76,0 +76,0 @@ ``` |
@@ -6,2 +6,3 @@ import { | ||
unlink as _unlink, | ||
readdir as _readdir, | ||
constants, | ||
@@ -198,1 +199,38 @@ } from 'fs' | ||
} | ||
/** Read a directory */ | ||
export function readdir(path: string): Promise<Array<string>> { | ||
return new Promise(function (resolve, reject) { | ||
_readdir(path, function (err, files) { | ||
if (err) return reject(new Errlop(`failed to read file at: ${path}`, err)) | ||
return resolve(files) | ||
}) | ||
}) | ||
} | ||
/** Read a directory safely */ | ||
export async function readDirectory(path: string): Promise<Array<string>> { | ||
// check exists | ||
try { | ||
await exists(path) | ||
} catch (err) { | ||
throw new Errlop(`unable to read the non-existent directory: ${path}`, err) | ||
} | ||
// check readable | ||
try { | ||
await readable(path) | ||
} catch (err) { | ||
throw new Errlop(`no read permission for the directory: ${path}`, err) | ||
} | ||
// attempt read | ||
try { | ||
return await readdir(path) | ||
} catch (err) { | ||
throw new Errlop( | ||
`failed to read the existing and readable directory: ${path}`, | ||
err | ||
) | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46462
865
1