@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,193 @@
|
|
|
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
|
+
import writeFile = require( './index' );
|
|
20
|
+
|
|
21
|
+
const onWrite = ( error: Error | null ): void => {
|
|
22
|
+
if ( error ) {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// TESTS //
|
|
29
|
+
|
|
30
|
+
// The function does not have a return value...
|
|
31
|
+
{
|
|
32
|
+
writeFile( './beep/boop.txt', 'beepboop', onWrite ); // $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
|
+
writeFile( false, 'beepboop', onWrite ); // $ExpectError
|
|
38
|
+
writeFile( true, 'beepboop', onWrite ); // $ExpectError
|
|
39
|
+
writeFile( null, 'beepboop', onWrite ); // $ExpectError
|
|
40
|
+
writeFile( undefined, 'beepboop', onWrite ); // $ExpectError
|
|
41
|
+
writeFile( [], 'beepboop', onWrite ); // $ExpectError
|
|
42
|
+
writeFile( {}, 'beepboop', onWrite ); // $ExpectError
|
|
43
|
+
writeFile( ( x: number ): number => x, 'beepboop', onWrite ); // $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
|
+
writeFile( './beep/boop.txt', false, onWrite ); // $ExpectError
|
|
49
|
+
writeFile( './beep/boop.txt', true, onWrite ); // $ExpectError
|
|
50
|
+
writeFile( './beep/boop.txt', null, onWrite ); // $ExpectError
|
|
51
|
+
writeFile( './beep/boop.txt', undefined, onWrite ); // $ExpectError
|
|
52
|
+
writeFile( './beep/boop.txt', [], onWrite ); // $ExpectError
|
|
53
|
+
writeFile( './beep/boop.txt', {}, onWrite ); // $ExpectError
|
|
54
|
+
writeFile( './beep/boop.txt', ( x: number ): number => x, onWrite ); // $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
|
+
writeFile( '/path/to/beepboop', 'beepboop', 'abc' ); // $ExpectError
|
|
60
|
+
writeFile( '/path/to/beepboop', 'beepboop', 1 ); // $ExpectError
|
|
61
|
+
writeFile( '/path/to/beepboop', 'beepboop', false ); // $ExpectError
|
|
62
|
+
writeFile( '/path/to/beepboop', 'beepboop', true ); // $ExpectError
|
|
63
|
+
writeFile( '/path/to/beepboop', 'beepboop', null ); // $ExpectError
|
|
64
|
+
writeFile( '/path/to/beepboop', 'beepboop', undefined ); // $ExpectError
|
|
65
|
+
writeFile( '/path/to/beepboop', 'beepboop', [] ); // $ExpectError
|
|
66
|
+
writeFile( '/path/to/beepboop', 'beepboop', {} ); // $ExpectError
|
|
67
|
+
writeFile( '/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
|
+
writeFile( '/path/to/beepboop', 'beepboop', false, onWrite ); // $ExpectError
|
|
73
|
+
writeFile( '/path/to/beepboop', 'beepboop', true, onWrite ); // $ExpectError
|
|
74
|
+
writeFile( '/path/to/beepboop', 'beepboop', null, onWrite ); // $ExpectError
|
|
75
|
+
writeFile( '/path/to/beepboop', 'beepboop', undefined, onWrite ); // $ExpectError
|
|
76
|
+
writeFile( '/path/to/beepboop', 'beepboop', 123, onWrite ); // $ExpectError
|
|
77
|
+
writeFile( '/path/to/beepboop', 'beepboop', [], onWrite ); // $ExpectError
|
|
78
|
+
writeFile( '/path/to/beepboop', 'beepboop', ( x: number ): number => x, onWrite ); // $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
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'encoding': 123 }, onWrite ); // $ExpectError
|
|
84
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'encoding': true }, onWrite ); // $ExpectError
|
|
85
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'encoding': false }, onWrite ); // $ExpectError
|
|
86
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'encoding': [] }, onWrite ); // $ExpectError
|
|
87
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'encoding': {} }, onWrite ); // $ExpectError
|
|
88
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'encoding': ( x: number ): number => x }, onWrite ); // $ExpectError
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// The compiler throws an error if the function is provided a `flag` option which is not a string...
|
|
92
|
+
{
|
|
93
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'flag': 123 }, onWrite ); // $ExpectError
|
|
94
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'flag': true }, onWrite ); // $ExpectError
|
|
95
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'flag': false }, onWrite ); // $ExpectError
|
|
96
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'flag': null }, onWrite ); // $ExpectError
|
|
97
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'flag': [] }, onWrite ); // $ExpectError
|
|
98
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'flag': {} }, onWrite ); // $ExpectError
|
|
99
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'flag': ( x: number ): number => x }, onWrite ); // $ExpectError
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// The compiler throws an error if the function is provided a `mode` option which is not a number...
|
|
103
|
+
{
|
|
104
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'mode': 'abc' }, onWrite ); // $ExpectError
|
|
105
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'mode': true }, onWrite ); // $ExpectError
|
|
106
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'mode': false }, onWrite ); // $ExpectError
|
|
107
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'mode': null }, onWrite ); // $ExpectError
|
|
108
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'mode': [] }, onWrite ); // $ExpectError
|
|
109
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'mode': {} }, onWrite ); // $ExpectError
|
|
110
|
+
writeFile( '/path/to/beepboop', 'beepboop', { 'mode': ( x: number ): number => x }, onWrite ); // $ExpectError
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// The compiler throws an error if the function is provided an unsupported number of arguments...
|
|
114
|
+
{
|
|
115
|
+
writeFile(); // $ExpectError
|
|
116
|
+
writeFile( 'C:\\foo\\bar\\baz\\beepboop' ); // $ExpectError
|
|
117
|
+
writeFile( '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
|
+
writeFile.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
|
+
writeFile.sync( false, 'beepboop' ); // $ExpectError
|
|
128
|
+
writeFile.sync( true, 'beepboop' ); // $ExpectError
|
|
129
|
+
writeFile.sync( null, 'beepboop' ); // $ExpectError
|
|
130
|
+
writeFile.sync( undefined, 'beepboop' ); // $ExpectError
|
|
131
|
+
writeFile.sync( [], 'beepboop' ); // $ExpectError
|
|
132
|
+
writeFile.sync( {}, 'beepboop' ); // $ExpectError
|
|
133
|
+
writeFile.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
|
+
writeFile.sync( '/path/to/beepboop', false ); // $ExpectError
|
|
139
|
+
writeFile.sync( '/path/to/beepboop', true ); // $ExpectError
|
|
140
|
+
writeFile.sync( '/path/to/beepboop', null ); // $ExpectError
|
|
141
|
+
writeFile.sync( '/path/to/beepboop', undefined ); // $ExpectError
|
|
142
|
+
writeFile.sync( '/path/to/beepboop', [] ); // $ExpectError
|
|
143
|
+
writeFile.sync( '/path/to/beepboop', {} ); // $ExpectError
|
|
144
|
+
writeFile.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
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', null ); // $ExpectError
|
|
150
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', true ); // $ExpectError
|
|
151
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', false ); // $ExpectError
|
|
152
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', 123 ); // $ExpectError
|
|
153
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', [] ); // $ExpectError
|
|
154
|
+
writeFile.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
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'encoding': 123 } ); // $ExpectError
|
|
160
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'encoding': true } ); // $ExpectError
|
|
161
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'encoding': false } ); // $ExpectError
|
|
162
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'encoding': [] } ); // $ExpectError
|
|
163
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'encoding': {} } ); // $ExpectError
|
|
164
|
+
writeFile.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
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'flag': 123 } ); // $ExpectError
|
|
170
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'flag': true } ); // $ExpectError
|
|
171
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'flag': false } ); // $ExpectError
|
|
172
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'flag': null } ); // $ExpectError
|
|
173
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'flag': [] } ); // $ExpectError
|
|
174
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'flag': {} } ); // $ExpectError
|
|
175
|
+
writeFile.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
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'mode': 'abc' } ); // $ExpectError
|
|
181
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'mode': true } ); // $ExpectError
|
|
182
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'mode': false } ); // $ExpectError
|
|
183
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'mode': null } ); // $ExpectError
|
|
184
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'mode': [] } ); // $ExpectError
|
|
185
|
+
writeFile.sync( '/path/to/beepboop', 'beepboop', { 'mode': {} } ); // $ExpectError
|
|
186
|
+
writeFile.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
|
+
writeFile.sync(); // $ExpectError
|
|
192
|
+
writeFile.sync( '/path/to/beepboop' ); // $ExpectError
|
|
193
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
* Write data to a file.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/fs/write-file
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var writeFile = require( '@stdlib/fs/write-file' );
|
|
28
|
+
*
|
|
29
|
+
* function onWrite( error ) {
|
|
30
|
+
* if ( error ) {
|
|
31
|
+
* throw error;
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* writeFile( './beep/boop.txt', 'beep boop\n', onWrite );
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var writeFileSync = require( '@stdlib/fs/write-file' ).sync;
|
|
39
|
+
*
|
|
40
|
+
* var err = writeFileSync( './beep/boop.txt', 'beep boop\n' );
|
|
41
|
+
* if ( err instanceof Error ) {
|
|
42
|
+
* throw err;
|
|
43
|
+
* }
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
// MODULES //
|
|
47
|
+
|
|
48
|
+
var setReadOnly = require( '@ohos-ports/stdlib-utils/define-nonenumerable-read-only-property' );
|
|
49
|
+
var main = require( './main.js' );
|
|
50
|
+
var sync = require( './sync.js' );
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// MAIN //
|
|
54
|
+
|
|
55
|
+
setReadOnly( main, 'sync', sync );
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// EXPORTS //
|
|
59
|
+
|
|
60
|
+
module.exports = main;
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var write = require( 'fs' ).writeFile;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// MAIN //
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Asynchronously writes data to a file.
|
|
30
|
+
*
|
|
31
|
+
* @param {(string|Buffer|integer)} file - file path or file descriptor
|
|
32
|
+
* @param {(string|Buffer)} data - data to write
|
|
33
|
+
* @param {(Object|string)} [options] - options
|
|
34
|
+
* @param {Function} clbk - callback to invoke after writing data to a file
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* function onWrite( error ) {
|
|
38
|
+
* if ( error ) {
|
|
39
|
+
* throw error;
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* writeFile( './beep/boop.txt', 'beep boop\n', onWrite );
|
|
44
|
+
*/
|
|
45
|
+
function writeFile() {
|
|
46
|
+
var args;
|
|
47
|
+
var i;
|
|
48
|
+
args = [];
|
|
49
|
+
for ( i = 0; i < arguments.length; i++ ) {
|
|
50
|
+
args.push( arguments[ i ] );
|
|
51
|
+
}
|
|
52
|
+
write.apply( null, args );
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// EXPORTS //
|
|
57
|
+
|
|
58
|
+
module.exports = writeFile;
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var writeFile = require( 'fs' ).writeFileSync;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// MAIN //
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Synchronously writes data to a file.
|
|
30
|
+
*
|
|
31
|
+
* @param {(string|Buffer|integer)} file - file path or file descriptor
|
|
32
|
+
* @param {(string|Buffer)} data - data to write
|
|
33
|
+
* @param {(Object|string)} [options] - options
|
|
34
|
+
* @returns {(Error|null)} error object or null
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var err = writeFileSync( './beep/boop.txt', 'beep boop\n' );
|
|
38
|
+
* if ( err instanceof Error ) {
|
|
39
|
+
* throw err;
|
|
40
|
+
* }
|
|
41
|
+
*/
|
|
42
|
+
function writeFileSync( file, data, options ) {
|
|
43
|
+
try {
|
|
44
|
+
if ( arguments.length > 2 ) {
|
|
45
|
+
writeFile( file, data, options );
|
|
46
|
+
} else {
|
|
47
|
+
writeFile( file, data );
|
|
48
|
+
}
|
|
49
|
+
} catch ( err ) {
|
|
50
|
+
return err;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// EXPORTS //
|
|
57
|
+
|
|
58
|
+
module.exports = writeFileSync;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/fs/write-file",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Write data to a file.",
|
|
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
|
+
"write-file": "./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
|
+
"writefile",
|
|
59
|
+
"writefilesync",
|
|
60
|
+
"path",
|
|
61
|
+
"async",
|
|
62
|
+
"sync",
|
|
63
|
+
"file",
|
|
64
|
+
"write",
|
|
65
|
+
"open",
|
|
66
|
+
"filesystem"
|
|
67
|
+
]
|
|
68
|
+
}
|