@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,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 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
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var close = require( 'fs' ).closeSync; // eslint-disable-line stdlib/no-redeclare
|
|
24
|
+
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
|
|
25
|
+
var format = require( '@stdlib/string/format' );
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// MAIN //
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Synchronously closes a file descriptor.
|
|
32
|
+
*
|
|
33
|
+
* @param {NonNegativeInteger} fd - file descriptor
|
|
34
|
+
* @throws {TypeError} must provide a valid file descriptor (nonnegative integer)
|
|
35
|
+
* @returns {(Error|void)} an error object or `undefined`
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var openSync = require( '@stdlib/fs/open' ).sync;
|
|
39
|
+
*
|
|
40
|
+
* var fd = openSync( __filename, 'r+' );
|
|
41
|
+
*
|
|
42
|
+
* if ( fd instanceof Error ) {
|
|
43
|
+
* throw fd;
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* var err = closeSync( fd );
|
|
47
|
+
* if ( err instanceof Error ) {
|
|
48
|
+
* throw err;
|
|
49
|
+
* }
|
|
50
|
+
*/
|
|
51
|
+
function closeSync( fd ) {
|
|
52
|
+
if ( !isNonNegativeInteger( fd ) ) {
|
|
53
|
+
throw new TypeError( format( 'invalid argument. Must provide a valid file descriptor (i.e., a nonnegative integer). Value: `%s`.', fd ) );
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
close( fd );
|
|
57
|
+
} catch ( err ) {
|
|
58
|
+
return err;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
// EXPORTS //
|
|
64
|
+
|
|
65
|
+
module.exports = closeSync;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/fs/close",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Close a file descriptor.",
|
|
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
|
+
"main": "./lib",
|
|
17
|
+
"directories": {
|
|
18
|
+
"benchmark": "./benchmark",
|
|
19
|
+
"doc": "./docs",
|
|
20
|
+
"example": "./examples",
|
|
21
|
+
"lib": "./lib",
|
|
22
|
+
"test": "./test"
|
|
23
|
+
},
|
|
24
|
+
"types": "./docs/types",
|
|
25
|
+
"scripts": {},
|
|
26
|
+
"homepage": "https://github.com/stdlib-js/stdlib",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git://github.com/stdlib-js/stdlib.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {},
|
|
35
|
+
"devDependencies": {},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=0.10.0",
|
|
38
|
+
"npm": ">2.7.0"
|
|
39
|
+
},
|
|
40
|
+
"os": [
|
|
41
|
+
"aix",
|
|
42
|
+
"darwin",
|
|
43
|
+
"freebsd",
|
|
44
|
+
"linux",
|
|
45
|
+
"macos",
|
|
46
|
+
"openbsd",
|
|
47
|
+
"sunos",
|
|
48
|
+
"win32",
|
|
49
|
+
"windows"
|
|
50
|
+
],
|
|
51
|
+
"keywords": [
|
|
52
|
+
"stdlib",
|
|
53
|
+
"stdfs",
|
|
54
|
+
"fs",
|
|
55
|
+
"close",
|
|
56
|
+
"closesync",
|
|
57
|
+
"path",
|
|
58
|
+
"async",
|
|
59
|
+
"sync",
|
|
60
|
+
"file",
|
|
61
|
+
"open",
|
|
62
|
+
"filesystem"
|
|
63
|
+
]
|
|
64
|
+
}
|
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2021 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
|
+
// TypeScript Version: 4.1
|
|
20
|
+
|
|
21
|
+
/* eslint-disable max-lines */
|
|
22
|
+
|
|
23
|
+
import appendFile = require( './../../append-file' );
|
|
24
|
+
import close = require( './../../close' );
|
|
25
|
+
import exists = require( './../../exists' );
|
|
26
|
+
import open = require( './../../open' );
|
|
27
|
+
import readDir = require( './../../read-dir' );
|
|
28
|
+
import readFile = require( './../../read-file' );
|
|
29
|
+
import readFileList = require( './../../read-file-list' );
|
|
30
|
+
import readJSON = require( './../../read-json' );
|
|
31
|
+
import readNDJSON = require( './../../read-ndjson' );
|
|
32
|
+
import readWASM = require( './../../read-wasm' );
|
|
33
|
+
import rename = require( './../../rename' );
|
|
34
|
+
import resolveParentPath = require( './../../resolve-parent-path' );
|
|
35
|
+
import resolveParentPathBy = require( './../../resolve-parent-path-by' );
|
|
36
|
+
import resolveParentPaths = require( './../../resolve-parent-paths' );
|
|
37
|
+
import unlink = require( './../../unlink' );
|
|
38
|
+
import writeFile = require( './../../write-file' );
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Interface describing the `fs` namespace.
|
|
42
|
+
*/
|
|
43
|
+
interface Namespace {
|
|
44
|
+
/**
|
|
45
|
+
* Asynchronously appends data to a file.
|
|
46
|
+
*
|
|
47
|
+
* @param path - file path or file descriptor
|
|
48
|
+
* @param data - data to append
|
|
49
|
+
* @param options - options (if a string, the value is the encoding)
|
|
50
|
+
* @param clbk - callback to invoke after appending data to a file
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* function onAppend( err ) {
|
|
54
|
+
* if ( err ) {
|
|
55
|
+
* console.log( err.message );
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* ns.appendFile( './beep/boop.txt', 'beep boop\n', onAppend );
|
|
60
|
+
*/
|
|
61
|
+
appendFile: typeof appendFile;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Asynchronously closes a file descriptor.
|
|
65
|
+
*
|
|
66
|
+
* @param fd - file descriptor
|
|
67
|
+
* @param clbk - callback to invoke after closing a file descriptor
|
|
68
|
+
* @throws first argument must be a valid file descriptor (nonnegative integer)
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* var openSync = require( './../../open' ).sync;
|
|
72
|
+
*
|
|
73
|
+
* function done( error ) {
|
|
74
|
+
* if ( error ) {
|
|
75
|
+
* throw error;
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
*
|
|
79
|
+
* var fd = openSync( __filename, 'r+' );
|
|
80
|
+
* if ( fd instanceof Error ) {
|
|
81
|
+
* throw fd;
|
|
82
|
+
* }
|
|
83
|
+
*
|
|
84
|
+
* ns.close( fd, done );
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* var openSync = require( './../../open' ).sync;
|
|
88
|
+
*
|
|
89
|
+
* var fd = openSync( __filename, 'r+' );
|
|
90
|
+
*
|
|
91
|
+
* if ( fd instanceof Error ) {
|
|
92
|
+
* throw fd;
|
|
93
|
+
* }
|
|
94
|
+
*
|
|
95
|
+
* var err = ns.close.sync( fd );
|
|
96
|
+
* if ( err instanceof Error ) {
|
|
97
|
+
* throw err;
|
|
98
|
+
* }
|
|
99
|
+
*/
|
|
100
|
+
close: typeof close;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Tests whether a path exists on the filesystem.
|
|
104
|
+
*
|
|
105
|
+
* @param path - path to test
|
|
106
|
+
* @param clbk - callback to invoke after testing path existence
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ns.exists( __dirname, done );
|
|
110
|
+
*
|
|
111
|
+
* function done( error, bool ) {
|
|
112
|
+
* if ( error ) {
|
|
113
|
+
* console.error( error );
|
|
114
|
+
* }
|
|
115
|
+
* if ( bool ) {
|
|
116
|
+
* console.log( '...path ns.exists.' );
|
|
117
|
+
* } else {
|
|
118
|
+
* console.log( '...path does not exist.' );
|
|
119
|
+
* }
|
|
120
|
+
* }
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* var bool = ns.exists.sync( __dirname );
|
|
124
|
+
* // returns <boolean>
|
|
125
|
+
*/
|
|
126
|
+
exists: typeof exists;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Asynchronously opens a file.
|
|
130
|
+
*
|
|
131
|
+
* @param path - file path
|
|
132
|
+
* @param flags - file system flags (default: 'r')
|
|
133
|
+
* @param mode - file mode (default: 0o666)
|
|
134
|
+
* @param clbk - callback to invoke after opening a file
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* var closeSync = require( './../../close' ).sync;
|
|
138
|
+
*
|
|
139
|
+
* function onOpen( error, fd ) {
|
|
140
|
+
* if ( error ) {
|
|
141
|
+
* throw error;
|
|
142
|
+
* }
|
|
143
|
+
* closeSync( fd );
|
|
144
|
+
* }
|
|
145
|
+
* ns.open( __filename, onOpen );
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* var closeSync = require( './../../close' ).sync;
|
|
149
|
+
*
|
|
150
|
+
* var fd = ns.open.sync( __filename );
|
|
151
|
+
* if ( fd instanceof Error ) {
|
|
152
|
+
* throw fd;
|
|
153
|
+
* }
|
|
154
|
+
* closeSync( fd );
|
|
155
|
+
*/
|
|
156
|
+
open: typeof open;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Asynchronously reads the contents of a directory.
|
|
160
|
+
*
|
|
161
|
+
* @param path - directory path
|
|
162
|
+
* @param clbk - callback to invoke after reading directory contents
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* function onRead( error, data ) {
|
|
166
|
+
* if ( error ) {
|
|
167
|
+
* console.error( error );
|
|
168
|
+
* } else {
|
|
169
|
+
* console.log( data );
|
|
170
|
+
* }
|
|
171
|
+
* }
|
|
172
|
+
* ns.readDir( __dirname, onRead );
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* var out = ns.readDir.sync( __dirname );
|
|
176
|
+
* if ( out instanceof Error ) {
|
|
177
|
+
* throw out;
|
|
178
|
+
* }
|
|
179
|
+
* console.log( out );
|
|
180
|
+
*/
|
|
181
|
+
readDir: typeof readDir;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Asynchronously reads the entire contents of a file.
|
|
185
|
+
*
|
|
186
|
+
* @param file - file path or file descriptor
|
|
187
|
+
* @param options - options
|
|
188
|
+
* @param options.encoding - file encoding
|
|
189
|
+
* @param options.flag - file status flag
|
|
190
|
+
* @param clbk - callback to invoke after reading file contents
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* function onFile( error, data ) {
|
|
194
|
+
* if ( error ) {
|
|
195
|
+
* throw error;
|
|
196
|
+
* }
|
|
197
|
+
* console.log( data );
|
|
198
|
+
* }
|
|
199
|
+
* ns.readFile( __filename, onFile );
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* var out = ns.readFile.sync( __filename );
|
|
203
|
+
* if ( out instanceof Error ) {
|
|
204
|
+
* throw out;
|
|
205
|
+
* }
|
|
206
|
+
* console.log( out );
|
|
207
|
+
*/
|
|
208
|
+
readFile: typeof readFile;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Asynchronously reads the entire contents of each file in a file list.
|
|
212
|
+
*
|
|
213
|
+
* @param list - list of file paths
|
|
214
|
+
* @param options - options
|
|
215
|
+
* @param options.encoding - file encoding
|
|
216
|
+
* @param options.flag - file status flag
|
|
217
|
+
* @param clbk - callback to invoke after reading file contents
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* var list = [ __filename ];
|
|
221
|
+
*
|
|
222
|
+
* ns.readFileList( list, onFiles );
|
|
223
|
+
*
|
|
224
|
+
* function onFiles( error, files ) {
|
|
225
|
+
* if ( error ) {
|
|
226
|
+
* throw error;
|
|
227
|
+
* }
|
|
228
|
+
* console.dir( files );
|
|
229
|
+
* }
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* var list = [ __filename ];
|
|
233
|
+
* var files = ns.readFileList.sync( list );
|
|
234
|
+
*
|
|
235
|
+
* if ( files instanceof Error ) {
|
|
236
|
+
* throw files;
|
|
237
|
+
* }
|
|
238
|
+
* console.dir( files );
|
|
239
|
+
*/
|
|
240
|
+
readFileList: typeof readFileList;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Asynchronously reads a file as JSON.
|
|
244
|
+
*
|
|
245
|
+
* @param file - file path or file descriptor
|
|
246
|
+
* @param options - options
|
|
247
|
+
* @param options.encoding - file encoding
|
|
248
|
+
* @param options.flag - file status flag
|
|
249
|
+
* @param options.reviver - JSON reviver
|
|
250
|
+
* @param clbk - callback
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* var resolve = require( 'path' ).resolve;
|
|
254
|
+
*
|
|
255
|
+
* ns.readJSON( resolve( __dirname, '..', 'package.json' ), 'utf-8', onJSON );
|
|
256
|
+
*
|
|
257
|
+
* function onJSON( error, data ) {
|
|
258
|
+
* if ( error ) {
|
|
259
|
+
* throw error;
|
|
260
|
+
* }
|
|
261
|
+
* console.dir( data );
|
|
262
|
+
* }
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* var resolve = require( 'path' ).resolve;
|
|
266
|
+
* var instanceOf = require( '@stdlib/assert/instance-of' );
|
|
267
|
+
*
|
|
268
|
+
* var out = ns.readJSON.sync( resolve( __dirname, '..', 'package.json' ) );
|
|
269
|
+
* if ( instanceOf( out, Error ) ) {
|
|
270
|
+
* throw out;
|
|
271
|
+
* }
|
|
272
|
+
* console.dir( out );
|
|
273
|
+
*/
|
|
274
|
+
readJSON: typeof readJSON;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Asynchronously reads a file as newline-delimited JSON.
|
|
278
|
+
*
|
|
279
|
+
* @param file - file path or file descriptor
|
|
280
|
+
* @param options - options
|
|
281
|
+
* @param options.encoding - file encoding
|
|
282
|
+
* @param options.flag - file status flag
|
|
283
|
+
* @param options.reviver - JSON reviver
|
|
284
|
+
* @param clbk - callback
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* var resolve = require( 'path' ).resolve;
|
|
288
|
+
*
|
|
289
|
+
* ns.readNDJSON( resolve( __dirname, '..', 'examples', 'fixtures', 'file.ndjson' ), 'utf-8', clbk );
|
|
290
|
+
*
|
|
291
|
+
* function clbk( error, data ) {
|
|
292
|
+
* if ( error ) {
|
|
293
|
+
* throw error;
|
|
294
|
+
* }
|
|
295
|
+
* console.log( data );
|
|
296
|
+
* }
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* var resolve = require( 'path' ).resolve;
|
|
300
|
+
* var instanceOf = require( '@stdlib/assert/instance-of' );
|
|
301
|
+
*
|
|
302
|
+
* var out = ns.readNDJSON.sync( resolve( __dirname, '..', 'examples', 'fixtures', 'file.ndjson' ) );
|
|
303
|
+
* if ( instanceOf( out, Error ) ) {
|
|
304
|
+
* throw out;
|
|
305
|
+
* }
|
|
306
|
+
* console.log( out );
|
|
307
|
+
*/
|
|
308
|
+
readNDJSON: typeof readNDJSON;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Reads the entire contents of a WebAssembly file.
|
|
312
|
+
*
|
|
313
|
+
* @param file - file path or file descriptor
|
|
314
|
+
* @param options - options
|
|
315
|
+
* @param options.flag - file status flag
|
|
316
|
+
* @param clbk - callback to invoke after reading a file
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* var join = require( 'path' ).join;
|
|
320
|
+
* var instanceOf = require( '@stdlib/assert/instance-of' );
|
|
321
|
+
*
|
|
322
|
+
* var fpath = join( __dirname, 'foo.wasm' );
|
|
323
|
+
* ns.readWASM( fpath, onRead );
|
|
324
|
+
*
|
|
325
|
+
* function onRead( error, buf ) {
|
|
326
|
+
* if ( error ) {
|
|
327
|
+
* throw error;
|
|
328
|
+
* }
|
|
329
|
+
* console.log( buf );
|
|
330
|
+
* }
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* var join = require( 'path' ).join;
|
|
334
|
+
* var instanceOf = require( '@stdlib/assert/instance-of' );
|
|
335
|
+
*
|
|
336
|
+
* var fpath = join( __dirname, 'foo.wasm' );
|
|
337
|
+
* var out = ns.readWASM.sync( fpath );
|
|
338
|
+
* if ( instanceOf( out, Error ) ) {
|
|
339
|
+
* throw out;
|
|
340
|
+
* }
|
|
341
|
+
* console.log( out );
|
|
342
|
+
*/
|
|
343
|
+
readWASM: typeof readWASM;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Asynchronously renames a file.
|
|
347
|
+
*
|
|
348
|
+
* @param oldPath - old path
|
|
349
|
+
* @param newPath - new path
|
|
350
|
+
* @param clbk - callback to invoke after renaming a path
|
|
351
|
+
*
|
|
352
|
+
* @example
|
|
353
|
+
* function done( error ) {
|
|
354
|
+
* if ( error ) {
|
|
355
|
+
* throw error;
|
|
356
|
+
* }
|
|
357
|
+
* }
|
|
358
|
+
*
|
|
359
|
+
* ns.rename( './beep/boop.txt', './beep/foo.txt', done );
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* var err = ns.rename.sync( './beep/boop.txt', './beep/foo.txt' );
|
|
363
|
+
* if ( err instanceof Error ) {
|
|
364
|
+
* throw err;
|
|
365
|
+
* }
|
|
366
|
+
*/
|
|
367
|
+
rename: typeof rename;
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Asynchronously resolves a path by walking parent directories.
|
|
371
|
+
*
|
|
372
|
+
* @param path - path to resolve
|
|
373
|
+
* @param options - function options
|
|
374
|
+
* @param options.dir - base directory
|
|
375
|
+
* @param clbk - callback to invoke after resolving a path
|
|
376
|
+
* @throws must provide valid options
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ns.resolveParentPath( 'package.json', onPath );
|
|
380
|
+
*
|
|
381
|
+
* function onPath( error, path ) {
|
|
382
|
+
* if ( error ) {
|
|
383
|
+
* throw error;
|
|
384
|
+
* }
|
|
385
|
+
* console.log( path );
|
|
386
|
+
* }
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* var path = ns.resolveParentPath.sync( 'package.json' );
|
|
390
|
+
*/
|
|
391
|
+
resolveParentPath: typeof resolveParentPath;
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Asynchronously resolves a path according to a predicate function by walking parent directories.
|
|
395
|
+
*
|
|
396
|
+
* @param path - path to resolve
|
|
397
|
+
* @param options - function options
|
|
398
|
+
* @param options.dir - base directory
|
|
399
|
+
* @param predicate - predicate function
|
|
400
|
+
* @param clbk - callback to invoke after resolving a path
|
|
401
|
+
* @throws must provide valid options
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ns.resolveParentPathBy( 'package.json', predicate, onPath );
|
|
405
|
+
*
|
|
406
|
+
* function predicate( path, next ) {
|
|
407
|
+
* next( null, true );
|
|
408
|
+
* }
|
|
409
|
+
*
|
|
410
|
+
* function onPath( error, path ) {
|
|
411
|
+
* if ( error ) {
|
|
412
|
+
* throw error;
|
|
413
|
+
* }
|
|
414
|
+
* console.log( path );
|
|
415
|
+
* }
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* function predicate() {
|
|
419
|
+
* return true;
|
|
420
|
+
* }
|
|
421
|
+
*
|
|
422
|
+
* var path = ns.resolveParentPathBy.sync( 'package.json', predicate );
|
|
423
|
+
* // e.g., returns '...'
|
|
424
|
+
*/
|
|
425
|
+
resolveParentPathBy: typeof resolveParentPathBy;
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Asynchronously resolves paths from a set of paths by walking parent directories.
|
|
429
|
+
*
|
|
430
|
+
* @param paths - paths to resolve
|
|
431
|
+
* @param options - function options
|
|
432
|
+
* @param options.dir - base directory
|
|
433
|
+
* @param options.mode - mode of operation
|
|
434
|
+
* @param clbk - callback to invoke after resolving paths
|
|
435
|
+
* @throws must provide valid options
|
|
436
|
+
*
|
|
437
|
+
* @example
|
|
438
|
+
* ns.resolveParentPaths( [ 'package.json', 'package-lock.json' ], onPaths );
|
|
439
|
+
*
|
|
440
|
+
* function onPaths( error, paths ) {
|
|
441
|
+
* if ( error ) {
|
|
442
|
+
* throw error;
|
|
443
|
+
* }
|
|
444
|
+
* console.log( paths );
|
|
445
|
+
* }
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* var paths = ns.resolveParentPaths.sync( [ 'package.json', 'package-lock.json' ] );
|
|
449
|
+
*/
|
|
450
|
+
resolveParentPaths: typeof resolveParentPaths;
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Asynchronously removes a directory entry.
|
|
454
|
+
*
|
|
455
|
+
* @param path - entry path
|
|
456
|
+
* @param clbk - callback to invoke after removing a directory entry
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* function done( error ) {
|
|
460
|
+
* if ( error ) {
|
|
461
|
+
* throw error;
|
|
462
|
+
* }
|
|
463
|
+
* }
|
|
464
|
+
* ns.unlink( './beep/boop.txt', done );
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* var err = ns.unlink.sync( './beep/boop.txt' );
|
|
468
|
+
* if ( err instanceof Error ) {
|
|
469
|
+
* throw err;
|
|
470
|
+
* }
|
|
471
|
+
*/
|
|
472
|
+
unlink: typeof unlink;
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Asynchronously writes data to a file.
|
|
476
|
+
*
|
|
477
|
+
* @param file - file path or file descriptor
|
|
478
|
+
* @param data - data to write
|
|
479
|
+
* @param options - options; if a string, the value is the encoding
|
|
480
|
+
* @param clbk - callback to invoke after writing data to a file
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* function onWrite( error ) {
|
|
484
|
+
* if ( error ) {
|
|
485
|
+
* throw error;
|
|
486
|
+
* }
|
|
487
|
+
* }
|
|
488
|
+
*
|
|
489
|
+
* ns.writeFile( './beep/boop.txt', 'beep boop\n', onWrite );
|
|
490
|
+
*/
|
|
491
|
+
writeFile: typeof writeFile;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Filesystem APIs.
|
|
496
|
+
*/
|
|
497
|
+
declare var ns: Namespace;
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
// EXPORTS //
|
|
501
|
+
|
|
502
|
+
export = ns;
|