@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,110 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2024 The Stdlib Authors.
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
'use strict';
|
|
22
|
+
|
|
23
|
+
// MODULES //
|
|
24
|
+
|
|
25
|
+
var resolve = require( 'path' ).resolve;
|
|
26
|
+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
|
|
27
|
+
var CLI = require( '@stdlib/cli/ctor' );
|
|
28
|
+
var stdin = require( '@stdlib/process/read-stdin' );
|
|
29
|
+
var cwd = require( '@stdlib/process/cwd' );
|
|
30
|
+
var appendFile = require( './../lib' );
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// MAIN //
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Main execution sequence.
|
|
37
|
+
*
|
|
38
|
+
* @private
|
|
39
|
+
* @returns {void}
|
|
40
|
+
*/
|
|
41
|
+
function main() {
|
|
42
|
+
var flags;
|
|
43
|
+
var fpath;
|
|
44
|
+
var args;
|
|
45
|
+
var opts;
|
|
46
|
+
var cli;
|
|
47
|
+
|
|
48
|
+
// Create a command-line interface:
|
|
49
|
+
cli = new CLI({
|
|
50
|
+
'pkg': require( './../package.json' ),
|
|
51
|
+
'options': require( './../etc/cli_opts.json' ),
|
|
52
|
+
'help': readFileSync(resolve( __dirname, '..', 'docs', 'usage.txt' ), {
|
|
53
|
+
'encoding': 'utf8'
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Get any provided command-line options:
|
|
58
|
+
flags = cli.flags();
|
|
59
|
+
if ( flags.help || flags.version ) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Get any provided command-line arguments:
|
|
64
|
+
args = cli.args();
|
|
65
|
+
|
|
66
|
+
opts = {};
|
|
67
|
+
if ( flags.encoding ) {
|
|
68
|
+
opts.encoding = flags.encoding;
|
|
69
|
+
}
|
|
70
|
+
if ( flags.flag ) {
|
|
71
|
+
opts.flag = flags.flag;
|
|
72
|
+
}
|
|
73
|
+
if ( flags.mode ) {
|
|
74
|
+
opts.mode = parseInt( flags.mode, 8 );
|
|
75
|
+
}
|
|
76
|
+
fpath = resolve( cwd(), args[0] );
|
|
77
|
+
|
|
78
|
+
// Gather data from `stdin`...
|
|
79
|
+
stdin( onRead );
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Callback invoked upon reading from `stdin`.
|
|
83
|
+
*
|
|
84
|
+
* @private
|
|
85
|
+
* @param {(Error|null)} error - error object
|
|
86
|
+
* @param {Buffer} data - data
|
|
87
|
+
* @returns {void}
|
|
88
|
+
*/
|
|
89
|
+
function onRead( error, data ) {
|
|
90
|
+
if ( error ) {
|
|
91
|
+
return cli.error( error );
|
|
92
|
+
}
|
|
93
|
+
appendFile( fpath, data, opts, onAppend );
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Callback invoked upon appending a file.
|
|
98
|
+
*
|
|
99
|
+
* @private
|
|
100
|
+
* @param {Error} [err] - error object
|
|
101
|
+
* @returns {void}
|
|
102
|
+
*/
|
|
103
|
+
function onAppend( err ) {
|
|
104
|
+
if ( err ) {
|
|
105
|
+
return cli.error( err );
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
main();
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
|
|
2
|
+
{{alias}}( path, data[, options], clbk )
|
|
3
|
+
Asynchronously appends data to a file.
|
|
4
|
+
|
|
5
|
+
Parameters
|
|
6
|
+
----------
|
|
7
|
+
path: string|Buffer|integer
|
|
8
|
+
Filename or file descriptor.
|
|
9
|
+
|
|
10
|
+
data: string|Buffer
|
|
11
|
+
Data to append.
|
|
12
|
+
|
|
13
|
+
options: Object|string (optional)
|
|
14
|
+
Options. If a string, the value is the encoding.
|
|
15
|
+
|
|
16
|
+
options.encoding: string|null (optional)
|
|
17
|
+
Encoding. Default: 'utf8'.
|
|
18
|
+
|
|
19
|
+
options.flag: string (optional)
|
|
20
|
+
Flag. Default: 'a'.
|
|
21
|
+
|
|
22
|
+
options.mode: integer (optional)
|
|
23
|
+
Mode. Default: 0o666.
|
|
24
|
+
|
|
25
|
+
clbk: Function
|
|
26
|
+
Callback to invoke upon appending data to the file.
|
|
27
|
+
|
|
28
|
+
Examples
|
|
29
|
+
--------
|
|
30
|
+
> function onAppend( err ) {
|
|
31
|
+
... if ( err ) {
|
|
32
|
+
... console.error( err.message );
|
|
33
|
+
... }
|
|
34
|
+
... };
|
|
35
|
+
> {{alias}}( './beep/boop.txt', 'beep boop', onAppend );
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
{{alias}}.sync( path, data[, options] )
|
|
39
|
+
Synchronously appends data to a file.
|
|
40
|
+
|
|
41
|
+
Parameters
|
|
42
|
+
----------
|
|
43
|
+
path: string|Buffer|integer
|
|
44
|
+
Filename or file descriptor.
|
|
45
|
+
|
|
46
|
+
data: string|Buffer
|
|
47
|
+
Data to append.
|
|
48
|
+
|
|
49
|
+
options: Object|string (optional)
|
|
50
|
+
Options. If a string, the value is the encoding.
|
|
51
|
+
|
|
52
|
+
options.encoding: string|null (optional)
|
|
53
|
+
Encoding. Default: 'utf8'.
|
|
54
|
+
|
|
55
|
+
options.flag: string (optional)
|
|
56
|
+
Flag. Default: 'a'.
|
|
57
|
+
|
|
58
|
+
options.mode: integer (optional)
|
|
59
|
+
Mode. Default: 0o666.
|
|
60
|
+
|
|
61
|
+
Returns
|
|
62
|
+
-------
|
|
63
|
+
err: Error|null
|
|
64
|
+
Error object or null.
|
|
65
|
+
|
|
66
|
+
Examples
|
|
67
|
+
--------
|
|
68
|
+
> var err = {{alias}}.sync( './beep/boop.txt', 'beep boop' );
|
|
69
|
+
|
|
70
|
+
See Also
|
|
71
|
+
--------
|
|
72
|
+
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
/// <reference types = 'node'/>
|
|
22
|
+
|
|
23
|
+
import { Buffer } from 'buffer';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Interface defining function options.
|
|
27
|
+
*/
|
|
28
|
+
interface Options {
|
|
29
|
+
/**
|
|
30
|
+
* Encoding (default: null).
|
|
31
|
+
*/
|
|
32
|
+
encoding?: string | null;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Flag (default: 'a').
|
|
36
|
+
*/
|
|
37
|
+
flag?: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Mode (default: 0o666)
|
|
41
|
+
*/
|
|
42
|
+
mode?: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Callback invoked upon writing data to a file.
|
|
47
|
+
*
|
|
48
|
+
* @param err - error object
|
|
49
|
+
*/
|
|
50
|
+
type Callback = ( err: Error | null ) => void;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Interface for appending a file.
|
|
54
|
+
*/
|
|
55
|
+
interface AppendFile {
|
|
56
|
+
/**
|
|
57
|
+
* Asynchronously appends data to a file.
|
|
58
|
+
*
|
|
59
|
+
* @param path - file path or file descriptor
|
|
60
|
+
* @param data - data to append
|
|
61
|
+
* @param options - options (if a string, the value is the encoding)
|
|
62
|
+
* @param clbk - callback to invoke after appending data to a file
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* function onAppend( err ) {
|
|
66
|
+
* if ( err ) {
|
|
67
|
+
* console.log( err.message );
|
|
68
|
+
* }
|
|
69
|
+
* }
|
|
70
|
+
*
|
|
71
|
+
* var opts = { 'flag': 'r' };
|
|
72
|
+
* appendFile( './beep/boop.txt', 'beep boop\n', opts, onAppend );
|
|
73
|
+
*/
|
|
74
|
+
( path: string | Buffer | number, data: string | Buffer, options: Options | string, clbk: Callback ): void;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Asynchronously appends data to a file.
|
|
78
|
+
*
|
|
79
|
+
* @param path - file path or file descriptor
|
|
80
|
+
* @param data - data to append
|
|
81
|
+
* @param clbk - callback to invoke after appending data to a file
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* function onAppend( err ) {
|
|
85
|
+
* if ( err ) {
|
|
86
|
+
* console.log( err.message );
|
|
87
|
+
* }
|
|
88
|
+
* }
|
|
89
|
+
*
|
|
90
|
+
* appendFile( './beep/boop.txt', 'beep boop\n', onAppend );
|
|
91
|
+
*/
|
|
92
|
+
( path: string | Buffer | number, data: string | Buffer, clbk: Callback ): void;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Synchronously appends data to a file.
|
|
96
|
+
*
|
|
97
|
+
* @param path - file path or file descriptor
|
|
98
|
+
* @param data - data to append
|
|
99
|
+
* @param options - options (if a string, the value is the encoding)
|
|
100
|
+
* @returns error object or null
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* var err = appendFile.sync( './beep/boop.txt', 'data to append\n' );
|
|
104
|
+
* if ( err instanceof Error ) {
|
|
105
|
+
* throw err;
|
|
106
|
+
* }
|
|
107
|
+
*/
|
|
108
|
+
sync( path: string | Buffer | number, data: string | Buffer, options?: Options | string ): Error | null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Asynchronously appends data to a file.
|
|
113
|
+
*
|
|
114
|
+
* @param path - file path or file descriptor
|
|
115
|
+
* @param data - data to append
|
|
116
|
+
* @param options - options (if a string, the value is the encoding)
|
|
117
|
+
* @param clbk - callback to invoke after appending data to a file
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* function onAppend( err ) {
|
|
121
|
+
* if ( err ) {
|
|
122
|
+
* console.log( err.message );
|
|
123
|
+
* }
|
|
124
|
+
* }
|
|
125
|
+
*
|
|
126
|
+
* appendFile( './beep/boop.txt', 'beep boop\n', onAppend );
|
|
127
|
+
*/
|
|
128
|
+
declare var appendFile: AppendFile;
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
// EXPORTS //
|
|
132
|
+
|
|
133
|
+
export = appendFile;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
import appendFile = require( './index' );
|
|
20
|
+
|
|
21
|
+
const onAppend = ( err: Error | null ): void => {
|
|
22
|
+
if ( err ) {
|
|
23
|
+
throw err;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// TESTS //
|
|
29
|
+
|
|
30
|
+
// The function does not have a return value...
|
|
31
|
+
{
|
|
32
|
+
appendFile( './beep/boop.txt', 'beepboop', onAppend ); // $ExpectType void
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The compiler throws an error if the function is provided a first argument which is not a string, buffer, or file descriptor...
|
|
36
|
+
{
|
|
37
|
+
appendFile( false, 'beepboop', onAppend ); // $ExpectError
|
|
38
|
+
appendFile( true, 'beepboop', onAppend ); // $ExpectError
|
|
39
|
+
appendFile( null, 'beepboop', onAppend ); // $ExpectError
|
|
40
|
+
appendFile( undefined, 'beepboop', onAppend ); // $ExpectError
|
|
41
|
+
appendFile( [], 'beepboop', onAppend ); // $ExpectError
|
|
42
|
+
appendFile( {}, 'beepboop', onAppend ); // $ExpectError
|
|
43
|
+
appendFile( ( x: number ): number => x, 'beepboop', onAppend ); // $ExpectError
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The compiler throws an error if the function is provided a second argument which is not a string or buffer...
|
|
47
|
+
{
|
|
48
|
+
appendFile( './beep/boop.txt', false, onAppend ); // $ExpectError
|
|
49
|
+
appendFile( './beep/boop.txt', true, onAppend ); // $ExpectError
|
|
50
|
+
appendFile( './beep/boop.txt', null, onAppend ); // $ExpectError
|
|
51
|
+
appendFile( './beep/boop.txt', undefined, onAppend ); // $ExpectError
|
|
52
|
+
appendFile( './beep/boop.txt', [], onAppend ); // $ExpectError
|
|
53
|
+
appendFile( './beep/boop.txt', {}, onAppend ); // $ExpectError
|
|
54
|
+
appendFile( './beep/boop.txt', ( x: number ): number => x, onAppend ); // $ExpectError
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// The compiler throws an error if the function is provided a callback argument which is not a function with the expected signature...
|
|
58
|
+
{
|
|
59
|
+
appendFile( '/path/to/beepboop', 'beepboop', 'abc' ); // $ExpectError
|
|
60
|
+
appendFile( '/path/to/beepboop', 'beepboop', 1 ); // $ExpectError
|
|
61
|
+
appendFile( '/path/to/beepboop', 'beepboop', false ); // $ExpectError
|
|
62
|
+
appendFile( '/path/to/beepboop', 'beepboop', true ); // $ExpectError
|
|
63
|
+
appendFile( '/path/to/beepboop', 'beepboop', null ); // $ExpectError
|
|
64
|
+
appendFile( '/path/to/beepboop', 'beepboop', undefined ); // $ExpectError
|
|
65
|
+
appendFile( '/path/to/beepboop', 'beepboop', [] ); // $ExpectError
|
|
66
|
+
appendFile( '/path/to/beepboop', 'beepboop', {} ); // $ExpectError
|
|
67
|
+
appendFile( '/path/to/beepboop', 'beepboop', ( x: number ): number => x ); // $ExpectError
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// The compiler throws an error if the function is provided an options argument which is not an object or string...
|
|
71
|
+
{
|
|
72
|
+
appendFile( '/path/to/beepboop', 'beepboop', false, onAppend ); // $ExpectError
|
|
73
|
+
appendFile( '/path/to/beepboop', 'beepboop', true, onAppend ); // $ExpectError
|
|
74
|
+
appendFile( '/path/to/beepboop', 'beepboop', null, onAppend ); // $ExpectError
|
|
75
|
+
appendFile( '/path/to/beepboop', 'beepboop', undefined, onAppend ); // $ExpectError
|
|
76
|
+
appendFile( '/path/to/beepboop', 'beepboop', 123, onAppend ); // $ExpectError
|
|
77
|
+
appendFile( '/path/to/beepboop', 'beepboop', [], onAppend ); // $ExpectError
|
|
78
|
+
appendFile( '/path/to/beepboop', 'beepboop', ( x: number ): number => x, onAppend ); // $ExpectError
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// The compiler throws an error if the function is provided an `encoding` option which is not a string or null...
|
|
82
|
+
{
|
|
83
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'encoding': 123 }, onAppend ); // $ExpectError
|
|
84
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'encoding': true }, onAppend ); // $ExpectError
|
|
85
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'encoding': false }, onAppend ); // $ExpectError
|
|
86
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'encoding': [] }, onAppend ); // $ExpectError
|
|
87
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'encoding': {} }, onAppend ); // $ExpectError
|
|
88
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'encoding': ( x: number ): number => x }, onAppend ); // $ExpectError
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// The compiler throws an error if the function is provided a `flag` option which is not a string...
|
|
92
|
+
{
|
|
93
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'flag': 123 }, onAppend ); // $ExpectError
|
|
94
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'flag': true }, onAppend ); // $ExpectError
|
|
95
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'flag': false }, onAppend ); // $ExpectError
|
|
96
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'flag': null }, onAppend ); // $ExpectError
|
|
97
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'flag': [] }, onAppend ); // $ExpectError
|
|
98
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'flag': {} }, onAppend ); // $ExpectError
|
|
99
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'flag': ( x: number ): number => x },onAppend ); // $ExpectError
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// The compiler throws an error if the function is provided a `mode` option which is not a number...
|
|
103
|
+
{
|
|
104
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'mode': 'abc' }, onAppend ); // $ExpectError
|
|
105
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'mode': true }, onAppend ); // $ExpectError
|
|
106
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'mode': false }, onAppend ); // $ExpectError
|
|
107
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'mode': null }, onAppend ); // $ExpectError
|
|
108
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'mode': [] }, onAppend ); // $ExpectError
|
|
109
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'mode': {} }, onAppend ); // $ExpectError
|
|
110
|
+
appendFile( '/path/to/beepboop', 'beepboop', { 'mode': ( x: number ): number => x }, onAppend ); // $ExpectError
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// The compiler throws an error if the function is provided an unsupported number of arguments...
|
|
114
|
+
{
|
|
115
|
+
appendFile(); // $ExpectError
|
|
116
|
+
appendFile( 'C:\\foo\\bar\\baz\\beepboop' ); // $ExpectError
|
|
117
|
+
appendFile( 'C:\\foo\\bar\\baz\\beepboop', 'beepboop' ); // $ExpectError
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Attached to main export is a `sync` method which returns an error or null...
|
|
121
|
+
{
|
|
122
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop' ); // $ExpectType Error | null
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// The compiler throws an error if the `sync` method is provided a first argument which is not a string, buffer, or file descriptor...
|
|
126
|
+
{
|
|
127
|
+
appendFile.sync( false, 'beepboop' ); // $ExpectError
|
|
128
|
+
appendFile.sync( true, 'beepboop' ); // $ExpectError
|
|
129
|
+
appendFile.sync( null, 'beepboop' ); // $ExpectError
|
|
130
|
+
appendFile.sync( undefined, 'beepboop' ); // $ExpectError
|
|
131
|
+
appendFile.sync( [], 'beepboop' ); // $ExpectError
|
|
132
|
+
appendFile.sync( {}, 'beepboop' ); // $ExpectError
|
|
133
|
+
appendFile.sync( ( x: number ): number => x, 'beepboop' ); // $ExpectError
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// The compiler throws an error if the `sync` method is provided a second argument which is not a string or buffer...
|
|
137
|
+
{
|
|
138
|
+
appendFile.sync( '/path/to/beepboop', false ); // $ExpectError
|
|
139
|
+
appendFile.sync( '/path/to/beepboop', true ); // $ExpectError
|
|
140
|
+
appendFile.sync( '/path/to/beepboop', null ); // $ExpectError
|
|
141
|
+
appendFile.sync( '/path/to/beepboop', undefined ); // $ExpectError
|
|
142
|
+
appendFile.sync( '/path/to/beepboop', [] ); // $ExpectError
|
|
143
|
+
appendFile.sync( '/path/to/beepboop', {} ); // $ExpectError
|
|
144
|
+
appendFile.sync( '/path/to/beepboop', ( x: number ): number => x ); // $ExpectError
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// The compiler throws an error if the `sync` method is provided an options argument which is not an object or string...
|
|
148
|
+
{
|
|
149
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', null ); // $ExpectError
|
|
150
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', true ); // $ExpectError
|
|
151
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', false ); // $ExpectError
|
|
152
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', 123 ); // $ExpectError
|
|
153
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', [] ); // $ExpectError
|
|
154
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', ( x: number ): number => x ); // $ExpectError
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// The compiler throws an error if the `sync` method is provided an `encoding` option which is not a string or null...
|
|
158
|
+
{
|
|
159
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'encoding': 123 } ); // $ExpectError
|
|
160
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'encoding': true } ); // $ExpectError
|
|
161
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'encoding': false } ); // $ExpectError
|
|
162
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'encoding': [] } ); // $ExpectError
|
|
163
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'encoding': {} } ); // $ExpectError
|
|
164
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'encoding': ( x: number ): number => x } ); // $ExpectError
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// The compiler throws an error if the `sync` method is provided a `flag` option which is not a string...
|
|
168
|
+
{
|
|
169
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'flag': 123 } ); // $ExpectError
|
|
170
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'flag': true } ); // $ExpectError
|
|
171
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'flag': false } ); // $ExpectError
|
|
172
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'flag': null } ); // $ExpectError
|
|
173
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'flag': [] } ); // $ExpectError
|
|
174
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'flag': {} } ); // $ExpectError
|
|
175
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'flag': ( x: number ): number => x } ); // $ExpectError
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// The compiler throws an error if the `sync` method is provided a `mode` option which is not a number...
|
|
179
|
+
{
|
|
180
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'mode': 'abc' } ); // $ExpectError
|
|
181
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'mode': true } ); // $ExpectError
|
|
182
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'mode': false } ); // $ExpectError
|
|
183
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'mode': null } ); // $ExpectError
|
|
184
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'mode': [] } ); // $ExpectError
|
|
185
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'mode': {} } ); // $ExpectError
|
|
186
|
+
appendFile.sync( '/path/to/beepboop', 'beepboop', { 'mode': ( x: number ): number => x } ); // $ExpectError
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// The compiler throws an error if the `sync` method is provided an unsupported number of arguments...
|
|
190
|
+
{
|
|
191
|
+
appendFile.sync(); // $ExpectError
|
|
192
|
+
appendFile.sync( '/path/to/beepboop' ); // $ExpectError
|
|
193
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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 append = require( 'fs' ).appendFile;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// MAIN //
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Asynchronously append data to a file, creating the file if it does not yet exist.
|
|
30
|
+
*
|
|
31
|
+
* @param {(string|Buffer|integer)} path - file path or file descriptor
|
|
32
|
+
* @param {(string|Buffer)} data - data to append
|
|
33
|
+
* @param {(Object|string)} [options] - options
|
|
34
|
+
* @param {Function} clbk - callback to invoke after appending data to the file
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* function onAppend( err ) {
|
|
38
|
+
* if ( err ) {
|
|
39
|
+
* console.log( err.message );
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* appendFile( './beep/boop.txt', 'appended something\n', onAppend );
|
|
44
|
+
*/
|
|
45
|
+
function appendFile() {
|
|
46
|
+
var args;
|
|
47
|
+
var i;
|
|
48
|
+
args = [];
|
|
49
|
+
for ( i = 0; i < arguments.length; i++ ) {
|
|
50
|
+
args.push( arguments[i] );
|
|
51
|
+
}
|
|
52
|
+
append.apply( null, args );
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// EXPORTS //
|
|
57
|
+
|
|
58
|
+
module.exports = appendFile;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
* Append data to a file.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/fs/append-file
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var appendFile = require( '@stdlib/fs/append-file' );
|
|
28
|
+
*
|
|
29
|
+
* function onAppend( err ) {
|
|
30
|
+
* if ( err ) {
|
|
31
|
+
* console.log( err.message );
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* appendFile( './beep/boop.txt', 'appended something\n', onAppend );
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var appendFileSync = require( '@stdlib/fs/append-file' ).sync;
|
|
39
|
+
*
|
|
40
|
+
* var err = appendFileSync( './beep/boop.txt', 'data to append\n' );
|
|
41
|
+
* if ( err instanceof Error ) {
|
|
42
|
+
* throw err;
|
|
43
|
+
* }
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// MODULES //
|
|
48
|
+
|
|
49
|
+
var setReadOnly = require( '@ohos-ports/stdlib-utils/define-nonenumerable-read-only-property' );
|
|
50
|
+
var async = require( './async.js' );
|
|
51
|
+
var sync = require( './sync.js' );
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
// MAIN //
|
|
55
|
+
|
|
56
|
+
setReadOnly( async, 'sync', sync );
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
// EXPORTS //
|
|
60
|
+
|
|
61
|
+
module.exports = async;
|