@ohos-ports/stdlib-fs 0.0.0-stage → 0.4.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +177 -0
- package/NOTICE +1 -0
- package/README.md +230 -2
- package/SECURITY.md +5 -0
- package/append-file/README.md +239 -0
- package/append-file/bin/cli +110 -0
- package/append-file/docs/repl.txt +72 -0
- package/append-file/docs/types/index.d.ts +133 -0
- package/append-file/docs/types/test.ts +193 -0
- package/append-file/docs/usage.txt +10 -0
- package/append-file/etc/cli_opts.json +22 -0
- package/append-file/lib/async.js +58 -0
- package/append-file/lib/index.js +61 -0
- package/append-file/lib/sync.js +58 -0
- package/append-file/package.json +69 -0
- package/close/README.md +172 -0
- package/close/docs/repl.txt +45 -0
- package/close/docs/types/index.d.ts +135 -0
- package/close/docs/types/test.ts +89 -0
- package/close/lib/index.js +73 -0
- package/close/lib/main.js +68 -0
- package/close/lib/sync.js +65 -0
- package/close/package.json +64 -0
- package/docs/types/index.d.ts +502 -0
- package/exists/README.md +252 -0
- package/exists/bin/cli +83 -0
- package/exists/docs/repl.txt +42 -0
- package/exists/docs/types/index.d.ts +112 -0
- package/exists/docs/types/test.ts +87 -0
- package/exists/docs/usage.txt +8 -0
- package/exists/etc/cli_opts.json +14 -0
- package/exists/lib/async.js +85 -0
- package/exists/lib/index.js +66 -0
- package/exists/lib/sync.js +62 -0
- package/exists/package.json +69 -0
- package/lib/index.js +186 -0
- package/open/README.md +204 -0
- package/open/docs/repl.txt +65 -0
- package/open/docs/types/index.d.ts +150 -0
- package/open/docs/types/test.ts +129 -0
- package/open/lib/defaults.json +4 -0
- package/open/lib/index.js +63 -0
- package/open/lib/main.js +64 -0
- package/open/lib/sync.js +68 -0
- package/open/package.json +64 -0
- package/package.json +67 -4
- package/read-dir/README.md +232 -0
- package/read-dir/bin/cli +83 -0
- package/read-dir/docs/repl.txt +44 -0
- package/read-dir/docs/types/index.d.ts +99 -0
- package/read-dir/docs/types/test.ts +85 -0
- package/read-dir/docs/usage.txt +8 -0
- package/read-dir/etc/cli_opts.json +14 -0
- package/read-dir/lib/async.js +57 -0
- package/read-dir/lib/index.js +62 -0
- package/read-dir/lib/sync.js +52 -0
- package/read-dir/package.json +69 -0
- package/read-file/README.md +246 -0
- package/read-file/bin/cli +91 -0
- package/read-file/docs/repl.txt +68 -0
- package/read-file/docs/types/index.d.ts +138 -0
- package/read-file/docs/types/test.ts +147 -0
- package/read-file/docs/usage.txt +10 -0
- package/read-file/etc/cli_opts.json +21 -0
- package/read-file/lib/index.js +61 -0
- package/read-file/lib/main.js +59 -0
- package/read-file/lib/sync.js +61 -0
- package/read-file/package.json +68 -0
- package/read-file-list/README.md +197 -0
- package/read-file-list/bin/cli +100 -0
- package/read-file-list/docs/repl.txt +81 -0
- package/read-file-list/docs/types/index.d.ts +166 -0
- package/read-file-list/docs/types/test.ts +166 -0
- package/read-file-list/docs/usage.txt +10 -0
- package/read-file-list/etc/cli_opts.json +21 -0
- package/read-file-list/lib/async.js +202 -0
- package/read-file-list/lib/clear_pending.js +47 -0
- package/read-file-list/lib/clear_timeout.js +23 -0
- package/read-file-list/lib/config.json +4 -0
- package/read-file-list/lib/delay.js +47 -0
- package/read-file-list/lib/index.js +66 -0
- package/read-file-list/lib/sync.js +94 -0
- package/read-file-list/package.json +72 -0
- package/read-json/README.md +176 -0
- package/read-json/docs/repl.txt +72 -0
- package/read-json/docs/types/index.d.ts +170 -0
- package/read-json/docs/types/test.ts +175 -0
- package/read-json/lib/async.js +114 -0
- package/read-json/lib/index.js +65 -0
- package/read-json/lib/sync.js +89 -0
- package/read-json/package.json +66 -0
- package/read-ndjson/README.md +166 -0
- package/read-ndjson/docs/repl.txt +72 -0
- package/read-ndjson/docs/types/index.d.ts +170 -0
- package/read-ndjson/docs/types/test.ts +179 -0
- package/read-ndjson/lib/async.js +114 -0
- package/read-ndjson/lib/index.js +65 -0
- package/read-ndjson/lib/sync.js +89 -0
- package/read-ndjson/package.json +68 -0
- package/read-wasm/README.md +158 -0
- package/read-wasm/docs/repl.txt +58 -0
- package/read-wasm/docs/types/index.d.ts +153 -0
- package/read-wasm/docs/types/test.ts +127 -0
- package/read-wasm/lib/async.js +106 -0
- package/read-wasm/lib/index.js +67 -0
- package/read-wasm/lib/sync.js +86 -0
- package/read-wasm/package.json +67 -0
- package/rename/README.md +259 -0
- package/rename/bin/cli +89 -0
- package/rename/docs/repl.txt +80 -0
- package/rename/docs/types/index.d.ts +109 -0
- package/rename/docs/types/test.ts +111 -0
- package/rename/docs/usage.txt +7 -0
- package/rename/etc/cli_opts.json +15 -0
- package/rename/lib/index.js +60 -0
- package/rename/lib/main.js +51 -0
- package/rename/lib/sync.js +53 -0
- package/rename/package.json +73 -0
- package/resolve-parent-path/README.md +204 -0
- package/resolve-parent-path/bin/cli +85 -0
- package/resolve-parent-path/docs/repl.txt +58 -0
- package/resolve-parent-path/docs/types/index.d.ts +128 -0
- package/resolve-parent-path/docs/types/test.ts +117 -0
- package/resolve-parent-path/docs/usage.txt +9 -0
- package/resolve-parent-path/etc/cli_opts.json +17 -0
- package/resolve-parent-path/lib/async.js +116 -0
- package/resolve-parent-path/lib/index.js +58 -0
- package/resolve-parent-path/lib/sync.js +83 -0
- package/resolve-parent-path/lib/validate.js +67 -0
- package/resolve-parent-path/package.json +78 -0
- package/resolve-parent-path-by/README.md +220 -0
- package/resolve-parent-path-by/docs/repl.txt +105 -0
- package/resolve-parent-path-by/docs/types/index.d.ts +220 -0
- package/resolve-parent-path-by/docs/types/test.ts +225 -0
- package/resolve-parent-path-by/lib/async.js +156 -0
- package/resolve-parent-path-by/lib/index.js +67 -0
- package/resolve-parent-path-by/lib/sync.js +98 -0
- package/resolve-parent-path-by/lib/validate.js +67 -0
- package/resolve-parent-path-by/package.json +76 -0
- package/resolve-parent-paths/README.md +228 -0
- package/resolve-parent-paths/bin/cli +93 -0
- package/resolve-parent-paths/docs/repl.txt +84 -0
- package/resolve-parent-paths/docs/types/index.d.ts +145 -0
- package/resolve-parent-paths/docs/types/test.ts +196 -0
- package/resolve-parent-paths/docs/usage.txt +10 -0
- package/resolve-parent-paths/etc/cli_opts.json +18 -0
- package/resolve-parent-paths/lib/index.js +60 -0
- package/resolve-parent-paths/lib/main.js +415 -0
- package/resolve-parent-paths/lib/sync.js +231 -0
- package/resolve-parent-paths/lib/validate.js +81 -0
- package/resolve-parent-paths/package.json +78 -0
- package/unlink/README.md +233 -0
- package/unlink/bin/cli +81 -0
- package/unlink/docs/repl.txt +62 -0
- package/unlink/docs/types/index.d.ts +105 -0
- package/unlink/docs/types/test.ts +85 -0
- package/unlink/docs/usage.txt +7 -0
- package/unlink/etc/cli_opts.json +15 -0
- package/unlink/lib/index.js +60 -0
- package/unlink/lib/main.js +50 -0
- package/unlink/lib/sync.js +52 -0
- package/unlink/package.json +70 -0
- package/write-file/README.md +250 -0
- package/write-file/bin/cli +110 -0
- package/write-file/docs/repl.txt +74 -0
- package/write-file/docs/types/index.d.ts +133 -0
- package/write-file/docs/types/test.ts +193 -0
- package/write-file/docs/usage.txt +10 -0
- package/write-file/etc/cli_opts.json +22 -0
- package/write-file/lib/index.js +60 -0
- package/write-file/lib/main.js +58 -0
- package/write-file/lib/sync.js +58 -0
- package/write-file/package.json +68 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Test whether a path exists on the filesystem. For more information, see the [archive][1].
|
|
23
|
+
*
|
|
24
|
+
* [1]: https://github.com/nodejs/node-v0.x-archive/blob/d8baf8a2a4481940bfed0196308ae6189ca18eee/lib/fs.js#L222
|
|
25
|
+
*
|
|
26
|
+
* @module @stdlib/fs/exists
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* var exists = require( '@stdlib/fs/exists' );
|
|
30
|
+
*
|
|
31
|
+
* exists( __dirname, done );
|
|
32
|
+
* exists( 'beepboop', done );
|
|
33
|
+
*
|
|
34
|
+
* function done( error, bool ) {
|
|
35
|
+
* if ( error ) {
|
|
36
|
+
* console.error( error.message );
|
|
37
|
+
* } else {
|
|
38
|
+
* console.log( bool );
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* var existsSync = require( '@stdlib/fs/exists' ).sync;
|
|
44
|
+
*
|
|
45
|
+
* console.log( existsSync( __dirname ) );
|
|
46
|
+
* // => true
|
|
47
|
+
*
|
|
48
|
+
* console.log( existsSync( 'beepboop' ) );
|
|
49
|
+
* // => false
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
// MODULES //
|
|
53
|
+
|
|
54
|
+
var setReadOnly = require( '@ohos-ports/stdlib-utils/define-nonenumerable-read-only-property' );
|
|
55
|
+
var exists = require( './async.js' );
|
|
56
|
+
var sync = require( './sync.js' );
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
// MAIN //
|
|
60
|
+
|
|
61
|
+
setReadOnly( exists, 'sync', sync );
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
// EXPORTS //
|
|
65
|
+
|
|
66
|
+
module.exports = exists;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/* eslint-disable no-sync */
|
|
20
|
+
|
|
21
|
+
'use strict';
|
|
22
|
+
|
|
23
|
+
// MODULES //
|
|
24
|
+
|
|
25
|
+
var fs = require( 'fs' );
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// FUNCTIONS //
|
|
29
|
+
|
|
30
|
+
var fcn;
|
|
31
|
+
if ( typeof fs.accessSync === 'function' ) {
|
|
32
|
+
fcn = fs.accessSync;
|
|
33
|
+
} else {
|
|
34
|
+
fcn = fs.statSync;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// MAIN //
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Synchronously tests whether a path exists on the filesystem.
|
|
42
|
+
*
|
|
43
|
+
* @param {(string|Buffer)} path - path to test
|
|
44
|
+
* @returns {boolean} boolean indicating whether the path exists
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* var bool = existsSync( __dirname );
|
|
48
|
+
* // returns <boolean>
|
|
49
|
+
*/
|
|
50
|
+
function existsSync( path ) {
|
|
51
|
+
try {
|
|
52
|
+
fcn( path );
|
|
53
|
+
} catch ( err ) { // eslint-disable-line no-unused-vars
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
// EXPORTS //
|
|
61
|
+
|
|
62
|
+
module.exports = existsSync;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/fs/exists",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Test whether a path exists on the filesystem.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"bin": {
|
|
17
|
+
"exists": "./bin/cli"
|
|
18
|
+
},
|
|
19
|
+
"main": "./lib",
|
|
20
|
+
"directories": {
|
|
21
|
+
"benchmark": "./benchmark",
|
|
22
|
+
"doc": "./docs",
|
|
23
|
+
"example": "./examples",
|
|
24
|
+
"lib": "./lib",
|
|
25
|
+
"test": "./test"
|
|
26
|
+
},
|
|
27
|
+
"types": "./docs/types",
|
|
28
|
+
"scripts": {},
|
|
29
|
+
"homepage": "https://github.com/stdlib-js/stdlib",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git://github.com/stdlib-js/stdlib.git"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {},
|
|
38
|
+
"devDependencies": {},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=0.10.0",
|
|
41
|
+
"npm": ">2.7.0"
|
|
42
|
+
},
|
|
43
|
+
"os": [
|
|
44
|
+
"aix",
|
|
45
|
+
"darwin",
|
|
46
|
+
"freebsd",
|
|
47
|
+
"linux",
|
|
48
|
+
"macos",
|
|
49
|
+
"openbsd",
|
|
50
|
+
"sunos",
|
|
51
|
+
"win32",
|
|
52
|
+
"windows"
|
|
53
|
+
],
|
|
54
|
+
"keywords": [
|
|
55
|
+
"stdlib",
|
|
56
|
+
"stdfs",
|
|
57
|
+
"fs",
|
|
58
|
+
"exists",
|
|
59
|
+
"existssync",
|
|
60
|
+
"polyfill",
|
|
61
|
+
"path",
|
|
62
|
+
"existence",
|
|
63
|
+
"check",
|
|
64
|
+
"async",
|
|
65
|
+
"sync",
|
|
66
|
+
"file",
|
|
67
|
+
"filesystem"
|
|
68
|
+
]
|
|
69
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// MODULES //
|
|
26
|
+
|
|
27
|
+
var setReadOnly = require( '@ohos-ports/stdlib-utils/define-read-only-property' );
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// MAIN //
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Top-level namespace.
|
|
34
|
+
*
|
|
35
|
+
* @namespace fs
|
|
36
|
+
*/
|
|
37
|
+
var fs = {};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @name appendFile
|
|
41
|
+
* @memberof fs
|
|
42
|
+
* @readonly
|
|
43
|
+
* @type {Function}
|
|
44
|
+
* @see {@link module:@stdlib/fs/append-file}
|
|
45
|
+
*/
|
|
46
|
+
setReadOnly( fs, 'appendFile', require( './../append-file' ) );
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @name close
|
|
50
|
+
* @memberof fs
|
|
51
|
+
* @readonly
|
|
52
|
+
* @type {Function}
|
|
53
|
+
* @see {@link module:@stdlib/fs/close}
|
|
54
|
+
*/
|
|
55
|
+
setReadOnly( fs, 'close', require( './../close' ) );
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @name exists
|
|
59
|
+
* @memberof fs
|
|
60
|
+
* @readonly
|
|
61
|
+
* @type {Function}
|
|
62
|
+
* @see {@link module:@stdlib/fs/exists}
|
|
63
|
+
*/
|
|
64
|
+
setReadOnly( fs, 'exists', require( './../exists' ) );
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @name open
|
|
68
|
+
* @memberof fs
|
|
69
|
+
* @readonly
|
|
70
|
+
* @type {Function}
|
|
71
|
+
* @see {@link module:@stdlib/fs/open}
|
|
72
|
+
*/
|
|
73
|
+
setReadOnly( fs, 'open', require( './../open' ) );
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @name readDir
|
|
77
|
+
* @memberof fs
|
|
78
|
+
* @readonly
|
|
79
|
+
* @type {Function}
|
|
80
|
+
* @see {@link module:@stdlib/fs/read-dir}
|
|
81
|
+
*/
|
|
82
|
+
setReadOnly( fs, 'readDir', require( './../read-dir' ) );
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @name readFile
|
|
86
|
+
* @memberof fs
|
|
87
|
+
* @readonly
|
|
88
|
+
* @type {Function}
|
|
89
|
+
* @see {@link module:@stdlib/fs/read-file}
|
|
90
|
+
*/
|
|
91
|
+
setReadOnly( fs, 'readFile', require( './../read-file' ) );
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @name readFileList
|
|
95
|
+
* @memberof fs
|
|
96
|
+
* @readonly
|
|
97
|
+
* @type {Function}
|
|
98
|
+
* @see {@link module:@stdlib/fs/read-file-list}
|
|
99
|
+
*/
|
|
100
|
+
setReadOnly( fs, 'readFileList', require( './../read-file-list' ) );
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @name readJSON
|
|
104
|
+
* @memberof fs
|
|
105
|
+
* @readonly
|
|
106
|
+
* @type {Function}
|
|
107
|
+
* @see {@link module:@stdlib/fs/read-json}
|
|
108
|
+
*/
|
|
109
|
+
setReadOnly( fs, 'readJSON', require( './../read-json' ) );
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @name readNDJSON
|
|
113
|
+
* @memberof fs
|
|
114
|
+
* @readonly
|
|
115
|
+
* @type {Function}
|
|
116
|
+
* @see {@link module:@stdlib/fs/read-ndjson}
|
|
117
|
+
*/
|
|
118
|
+
setReadOnly( fs, 'readNDJSON', require( './../read-ndjson' ) );
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @name readWASM
|
|
122
|
+
* @memberof fs
|
|
123
|
+
* @readonly
|
|
124
|
+
* @type {Function}
|
|
125
|
+
* @see {@link module:@stdlib/fs/read-wasm}
|
|
126
|
+
*/
|
|
127
|
+
setReadOnly( fs, 'readWASM', require( './../read-wasm' ) );
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @name rename
|
|
131
|
+
* @memberof fs
|
|
132
|
+
* @readonly
|
|
133
|
+
* @type {Function}
|
|
134
|
+
* @see {@link module:@stdlib/fs/rename}
|
|
135
|
+
*/
|
|
136
|
+
setReadOnly( fs, 'rename', require( './../rename' ) );
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @name resolveParentPath
|
|
140
|
+
* @memberof fs
|
|
141
|
+
* @readonly
|
|
142
|
+
* @type {Function}
|
|
143
|
+
* @see {@link module:@stdlib/fs/resolve-parent-path}
|
|
144
|
+
*/
|
|
145
|
+
setReadOnly( fs, 'resolveParentPath', require( './../resolve-parent-path' ) );
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @name resolveParentPathBy
|
|
149
|
+
* @memberof fs
|
|
150
|
+
* @readonly
|
|
151
|
+
* @type {Function}
|
|
152
|
+
* @see {@link module:@stdlib/fs/resolve-parent-path-by}
|
|
153
|
+
*/
|
|
154
|
+
setReadOnly( fs, 'resolveParentPathBy', require( './../resolve-parent-path-by' ) );
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @name resolveParentPaths
|
|
158
|
+
* @memberof fs
|
|
159
|
+
* @readonly
|
|
160
|
+
* @type {Function}
|
|
161
|
+
* @see {@link module:@stdlib/fs/resolve-parent-paths}
|
|
162
|
+
*/
|
|
163
|
+
setReadOnly( fs, 'resolveParentPaths', require( './../resolve-parent-paths' ) );
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @name unlink
|
|
167
|
+
* @memberof fs
|
|
168
|
+
* @readonly
|
|
169
|
+
* @type {Function}
|
|
170
|
+
* @see {@link module:@stdlib/fs/unlink}
|
|
171
|
+
*/
|
|
172
|
+
setReadOnly( fs, 'unlink', require( './../unlink' ) );
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @name writeFile
|
|
176
|
+
* @memberof fs
|
|
177
|
+
* @readonly
|
|
178
|
+
* @type {Function}
|
|
179
|
+
* @see {@link module:@stdlib/fs/write-file}
|
|
180
|
+
*/
|
|
181
|
+
setReadOnly( fs, 'writeFile', require( './../write-file' ) );
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
// EXPORTS //
|
|
185
|
+
|
|
186
|
+
module.exports = fs;
|
package/open/README.md
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@license Apache-2.0
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2019 The Stdlib Authors.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
-->
|
|
20
|
+
|
|
21
|
+
# Open
|
|
22
|
+
|
|
23
|
+
> Open a file.
|
|
24
|
+
|
|
25
|
+
<section class="usage">
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
<!-- eslint-disable stdlib/no-redeclare -->
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
var open = require( '@stdlib/fs/open' );
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
#### open( path\[, flags\[, mode]], clbk )
|
|
36
|
+
|
|
37
|
+
Asynchronously opens a file.
|
|
38
|
+
|
|
39
|
+
<!-- eslint-disable stdlib/no-redeclare -->
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
var closeSync = require( '@stdlib/fs/close' ).sync;
|
|
43
|
+
|
|
44
|
+
open( __filename, onOpen );
|
|
45
|
+
|
|
46
|
+
function onOpen( error, fd ) {
|
|
47
|
+
if ( error ) {
|
|
48
|
+
console.error( error.message );
|
|
49
|
+
} else {
|
|
50
|
+
closeSync( fd );
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The function has the same default parameter values as [`fs.open()`][node-fs].
|
|
56
|
+
|
|
57
|
+
#### open.sync( file\[, flags\[, mode]] )
|
|
58
|
+
|
|
59
|
+
Synchronously opens a `file`.
|
|
60
|
+
|
|
61
|
+
<!-- eslint-disable stdlib/no-redeclare -->
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
var closeSync = require( '@stdlib/fs/close' ).sync;
|
|
65
|
+
|
|
66
|
+
var fd = open.sync( __filename );
|
|
67
|
+
if ( fd instanceof Error ) {
|
|
68
|
+
console.error( fd.message );
|
|
69
|
+
} else {
|
|
70
|
+
closeSync( fd );
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The function has the same default parameters as [`fs.openSync()`][node-fs].
|
|
75
|
+
|
|
76
|
+
</section>
|
|
77
|
+
|
|
78
|
+
<!-- /.usage -->
|
|
79
|
+
|
|
80
|
+
<section class="notes">
|
|
81
|
+
|
|
82
|
+
## Notes
|
|
83
|
+
|
|
84
|
+
- The difference between this API and [`fs.openSync()`][node-fs] is that [`fs.openSync()`][node-fs] will throw if an `error` is encountered (e.g., if given a non-existent `path`) and this API will return an `error`. Hence, the following anti-pattern
|
|
85
|
+
|
|
86
|
+
<!-- eslint-disable stdlib/no-redeclare -->
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
var fs = require( 'fs' );
|
|
90
|
+
|
|
91
|
+
var fpath = '/path/to/file.js';
|
|
92
|
+
var fd;
|
|
93
|
+
|
|
94
|
+
// Check for existence to prevent an error being thrown...
|
|
95
|
+
if ( fs.existsSync( fpath ) ) {
|
|
96
|
+
fd = fs.readFileSync( fpath );
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
can be replaced by an approach which addresses existence via `error` handling.
|
|
101
|
+
|
|
102
|
+
<!-- eslint-disable stdlib/no-redeclare -->
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
var open = require( '@stdlib/fs/open' );
|
|
106
|
+
|
|
107
|
+
var fpath = '/path/to/file.js';
|
|
108
|
+
|
|
109
|
+
// Explicitly handle the error...
|
|
110
|
+
var fd = open.sync( fpath );
|
|
111
|
+
if ( fd instanceof Error ) {
|
|
112
|
+
// You choose what to do...
|
|
113
|
+
console.error( fd.message );
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
</section>
|
|
118
|
+
|
|
119
|
+
<!-- /.notes -->
|
|
120
|
+
|
|
121
|
+
<section class="examples">
|
|
122
|
+
|
|
123
|
+
## Examples
|
|
124
|
+
|
|
125
|
+
<!-- eslint-disable stdlib/no-redeclare -->
|
|
126
|
+
|
|
127
|
+
<!-- eslint no-undef: "error" -->
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
var join = require( 'path' ).join;
|
|
131
|
+
var closeSync = require( '@stdlib/fs/close' ).sync;
|
|
132
|
+
var open = require( '@stdlib/fs/open' );
|
|
133
|
+
|
|
134
|
+
/* Sync */
|
|
135
|
+
|
|
136
|
+
var fd = open.sync( join( __dirname, 'package.json' ), 'r+' );
|
|
137
|
+
// returns <number>
|
|
138
|
+
|
|
139
|
+
if ( fd instanceof Error ) {
|
|
140
|
+
console.error( fd.message );
|
|
141
|
+
} else {
|
|
142
|
+
closeSync( fd );
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
fd = open.sync( 'beepboop' );
|
|
146
|
+
// returns <Error>
|
|
147
|
+
|
|
148
|
+
/* Async */
|
|
149
|
+
|
|
150
|
+
open( join( __dirname, 'package.json' ), onOpen );
|
|
151
|
+
open( 'beepboop', onOpen );
|
|
152
|
+
|
|
153
|
+
function onOpen( error, fd ) {
|
|
154
|
+
if ( error ) {
|
|
155
|
+
if ( error.code === 'ENOENT' ) {
|
|
156
|
+
console.error( 'File does not exist.' );
|
|
157
|
+
} else {
|
|
158
|
+
console.error( error.message );
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
closeSync( fd );
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
</section>
|
|
167
|
+
|
|
168
|
+
<!-- /.examples -->
|
|
169
|
+
|
|
170
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
171
|
+
|
|
172
|
+
<section class="related">
|
|
173
|
+
|
|
174
|
+
* * *
|
|
175
|
+
|
|
176
|
+
## See Also
|
|
177
|
+
|
|
178
|
+
- <span class="package-name">[`@stdlib/fs/close`][@stdlib/fs/close]</span><span class="delimiter">: </span><span class="description">close a file descriptor.</span>
|
|
179
|
+
- <span class="package-name">[`@stdlib/fs/exists`][@stdlib/fs/exists]</span><span class="delimiter">: </span><span class="description">test whether a path exists on the filesystem.</span>
|
|
180
|
+
- <span class="package-name">[`@stdlib/fs/read-file`][@stdlib/fs/read-file]</span><span class="delimiter">: </span><span class="description">read the entire contents of a file.</span>
|
|
181
|
+
|
|
182
|
+
</section>
|
|
183
|
+
|
|
184
|
+
<!-- /.related -->
|
|
185
|
+
|
|
186
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
187
|
+
|
|
188
|
+
<section class="links">
|
|
189
|
+
|
|
190
|
+
[node-fs]: https://nodejs.org/api/fs.html
|
|
191
|
+
|
|
192
|
+
<!-- <related-links> -->
|
|
193
|
+
|
|
194
|
+
[@stdlib/fs/close]: https://github.com/stdlib-js/fs/tree/main/close
|
|
195
|
+
|
|
196
|
+
[@stdlib/fs/exists]: https://github.com/stdlib-js/fs/tree/main/exists
|
|
197
|
+
|
|
198
|
+
[@stdlib/fs/read-file]: https://github.com/stdlib-js/fs/tree/main/read-file
|
|
199
|
+
|
|
200
|
+
<!-- </related-links> -->
|
|
201
|
+
|
|
202
|
+
</section>
|
|
203
|
+
|
|
204
|
+
<!-- /.links -->
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
|
|
2
|
+
{{alias}}( path[, flags[, mode]], clbk )
|
|
3
|
+
Asynchronously opens a file.
|
|
4
|
+
|
|
5
|
+
Some characters, such as <>:"/\|?*, are reserved under Windows.
|
|
6
|
+
Under NTFS, if the path contains a colon, Node.js will open a file system
|
|
7
|
+
stream.
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
path: string|Buffer
|
|
12
|
+
Filename.
|
|
13
|
+
|
|
14
|
+
flags: string|number (optional)
|
|
15
|
+
File system flags. Default: 'r'.
|
|
16
|
+
|
|
17
|
+
mode: integer (optional)
|
|
18
|
+
File mode (permission and sticky bits). This sets the file mode, but
|
|
19
|
+
only if the file was created. On Windows, only the write permission can
|
|
20
|
+
be manipulated. Default: 0o666.
|
|
21
|
+
|
|
22
|
+
clbk: Function
|
|
23
|
+
Callback to invoke upon opening a file.
|
|
24
|
+
|
|
25
|
+
Examples
|
|
26
|
+
--------
|
|
27
|
+
> function onOpen( error, fd ) {
|
|
28
|
+
... if ( error ) {
|
|
29
|
+
... console.error( error.message );
|
|
30
|
+
... } else {
|
|
31
|
+
... {{alias:@stdlib/fs/close}}.sync( fd );
|
|
32
|
+
... }
|
|
33
|
+
... };
|
|
34
|
+
> {{alias}}( './beep/boop.txt', onOpen );
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
{{alias}}.sync( path[, flags[, mode]] )
|
|
38
|
+
Synchronously opens a file.
|
|
39
|
+
|
|
40
|
+
Parameters
|
|
41
|
+
----------
|
|
42
|
+
path: string|Buffer
|
|
43
|
+
Filename.
|
|
44
|
+
|
|
45
|
+
flags: string|number (optional)
|
|
46
|
+
File system flags. Default: 'r'.
|
|
47
|
+
|
|
48
|
+
mode: integer (optional)
|
|
49
|
+
File mode (permission and sticky bits). This sets the file mode, but
|
|
50
|
+
only if the file was created. On Windows, only the write permission can
|
|
51
|
+
be manipulated. Default: 0o666.
|
|
52
|
+
|
|
53
|
+
Returns
|
|
54
|
+
-------
|
|
55
|
+
fd: Error|integer
|
|
56
|
+
File descriptor.
|
|
57
|
+
|
|
58
|
+
Examples
|
|
59
|
+
--------
|
|
60
|
+
> var fd = {{alias}}.sync( './beep/boop.txt' );
|
|
61
|
+
> if ( !{{alias:@stdlib/assert/is-error}}( fd ) ) { {{alias:@stdlib/fs/close}}.sync( fd ); };
|
|
62
|
+
|
|
63
|
+
See Also
|
|
64
|
+
--------
|
|
65
|
+
|