@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,150 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020 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
|
+
* Callback invoked after opening a file.
|
|
27
|
+
*
|
|
28
|
+
* @param err - error argument
|
|
29
|
+
* @param fd - file descriptor
|
|
30
|
+
*/
|
|
31
|
+
type Callback = ( err: Error, fd: number ) => void;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Interface for opening a file.
|
|
35
|
+
*/
|
|
36
|
+
interface Open {
|
|
37
|
+
/**
|
|
38
|
+
* Asynchronously opens a file.
|
|
39
|
+
*
|
|
40
|
+
* @param path - file path
|
|
41
|
+
* @param flags - file system flags (default: 'r')
|
|
42
|
+
* @param mode - file mode (default: 0o666)
|
|
43
|
+
* @param clbk - callback to invoke after opening a file
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* var closeSync = require( './../../../close' ).sync;
|
|
47
|
+
*
|
|
48
|
+
* function onOpen( error, fd ) {
|
|
49
|
+
* if ( error ) {
|
|
50
|
+
* throw error;
|
|
51
|
+
* }
|
|
52
|
+
* closeSync( fd );
|
|
53
|
+
* }
|
|
54
|
+
* open( __filename, 'r+', 438, onOpen );
|
|
55
|
+
*/
|
|
56
|
+
( path: string | Buffer, flags: string | number, mode: number, clbk: Callback ): void;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Asynchronously opens a file.
|
|
60
|
+
*
|
|
61
|
+
* @param path - file path
|
|
62
|
+
* @param flags - file system flags (default: 'r')
|
|
63
|
+
* @param clbk - callback to invoke after opening a file
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* var closeSync = require( './../../../close' ).sync;
|
|
67
|
+
*
|
|
68
|
+
* function onOpen( error, fd ) {
|
|
69
|
+
* if ( error ) {
|
|
70
|
+
* throw error;
|
|
71
|
+
* }
|
|
72
|
+
* closeSync( fd );
|
|
73
|
+
* }
|
|
74
|
+
* open( __filename, 'r+', onOpen );
|
|
75
|
+
*/
|
|
76
|
+
( path: string | Buffer, flags: string | number, clbk: Callback ): void;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Asynchronously opens a file.
|
|
80
|
+
*
|
|
81
|
+
* @param path - file path
|
|
82
|
+
* @param clbk - callback to invoke after opening a file
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* var closeSync = require( './../../../close' ).sync;
|
|
86
|
+
*
|
|
87
|
+
* function onOpen( error, fd ) {
|
|
88
|
+
* if ( error ) {
|
|
89
|
+
* throw error;
|
|
90
|
+
* }
|
|
91
|
+
* closeSync( fd );
|
|
92
|
+
* }
|
|
93
|
+
* open( __filename, onOpen );
|
|
94
|
+
*/
|
|
95
|
+
( path: string | Buffer, clbk: Callback ): void;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Synchronously opens a file.
|
|
99
|
+
*
|
|
100
|
+
* @param path - file path
|
|
101
|
+
* @param flags - file system flags (default: 'r')
|
|
102
|
+
* @param mode - file mode (default: 0o666)
|
|
103
|
+
* @returns file descriptor or an error
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* var closeSync = require( './../../../close' ).sync;
|
|
107
|
+
*
|
|
108
|
+
* var fd = open.sync( __filename, 'r+' );
|
|
109
|
+
* if ( fd instanceof Error ) {
|
|
110
|
+
* throw fd;
|
|
111
|
+
* }
|
|
112
|
+
* closeSync( fd );
|
|
113
|
+
*/
|
|
114
|
+
sync( path: string | Buffer, flags?: string | number, mode?: number ): number | Error;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Asynchronously opens a file.
|
|
119
|
+
*
|
|
120
|
+
* @param path - file path
|
|
121
|
+
* @param flags - file system flags (default: 'r')
|
|
122
|
+
* @param mode - file mode (default: 0o666)
|
|
123
|
+
* @param clbk - callback to invoke after opening a file
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* var closeSync = require( '@stdlib/fs/close' ).sync;
|
|
127
|
+
*
|
|
128
|
+
* function onOpen( error, fd ) {
|
|
129
|
+
* if ( error ) {
|
|
130
|
+
* throw error;
|
|
131
|
+
* }
|
|
132
|
+
* closeSync( fd );
|
|
133
|
+
* }
|
|
134
|
+
* open( __filename, onOpen );
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* var closeSync = require( '@stdlib/fs/close' ).sync;
|
|
138
|
+
*
|
|
139
|
+
* var fd = open.sync( __filename );
|
|
140
|
+
* if ( fd instanceof Error ) {
|
|
141
|
+
* throw fd;
|
|
142
|
+
* }
|
|
143
|
+
* closeSync( fd );
|
|
144
|
+
*/
|
|
145
|
+
declare var open: Open;
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
// EXPORTS //
|
|
149
|
+
|
|
150
|
+
export = open;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020 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 open = require( './index' );
|
|
20
|
+
|
|
21
|
+
const done = ( error: Error, fd: number ) => {
|
|
22
|
+
if ( error || !fd ) {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// TESTS //
|
|
29
|
+
|
|
30
|
+
// The function does not have a return value...
|
|
31
|
+
{
|
|
32
|
+
open( '/path/to/beepboop', done ); // $ExpectType void
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The compiler throws an error if the function is provided a first argument which is not a string...
|
|
36
|
+
{
|
|
37
|
+
open( 123, done ); // $ExpectError
|
|
38
|
+
open( false, done ); // $ExpectError
|
|
39
|
+
open( true, done ); // $ExpectError
|
|
40
|
+
open( null, done ); // $ExpectError
|
|
41
|
+
open( undefined, done ); // $ExpectError
|
|
42
|
+
open( [], done ); // $ExpectError
|
|
43
|
+
open( {}, done ); // $ExpectError
|
|
44
|
+
open( ( x: number ): number => x, done ); // $ExpectError
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The compiler throws an error if the function is provided a last argument which is not a function with the expected signature...
|
|
48
|
+
{
|
|
49
|
+
open( '/path/to/beepboop', 'abc' ); // $ExpectError
|
|
50
|
+
open( '/path/to/beepboop', 123 ); // $ExpectError
|
|
51
|
+
open( '/path/to/beepboop', false ); // $ExpectError
|
|
52
|
+
open( '/path/to/beepboop', true ); // $ExpectError
|
|
53
|
+
open( '/path/to/beepboop', null ); // $ExpectError
|
|
54
|
+
open( '/path/to/beepboop', undefined ); // $ExpectError
|
|
55
|
+
open( '/path/to/beepboop', [] ); // $ExpectError
|
|
56
|
+
open( '/path/to/beepboop', {} ); // $ExpectError
|
|
57
|
+
open( '/path/to/beepboop', ( x: number ): number => x ); // $ExpectError
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The compiler throws an error if the function is provided a `flags` argument which is not a string or number...
|
|
61
|
+
{
|
|
62
|
+
open( '/path/to/beepboop', false, done ); // $ExpectError
|
|
63
|
+
open( '/path/to/beepboop', true, done ); // $ExpectError
|
|
64
|
+
open( '/path/to/beepboop', null, done ); // $ExpectError
|
|
65
|
+
open( '/path/to/beepboop', undefined, done ); // $ExpectError
|
|
66
|
+
open( '/path/to/beepboop', [], done ); // $ExpectError
|
|
67
|
+
open( '/path/to/beepboop', {}, done ); // $ExpectError
|
|
68
|
+
open( '/path/to/beepboop', ( x: number ): number => x, done ); // $ExpectError
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// The compiler throws an error if the function is provided a `mode` argument which is not a number...
|
|
72
|
+
{
|
|
73
|
+
open( '/path/to/beepboop', 'r+', 'abc', done ); // $ExpectError
|
|
74
|
+
open( '/path/to/beepboop', 'r+', false, done ); // $ExpectError
|
|
75
|
+
open( '/path/to/beepboop', 'r+', true, done ); // $ExpectError
|
|
76
|
+
open( '/path/to/beepboop', 'r+', null, done ); // $ExpectError
|
|
77
|
+
open( '/path/to/beepboop', 'r+', undefined, done ); // $ExpectError
|
|
78
|
+
open( '/path/to/beepboop', 'r+', [], done ); // $ExpectError
|
|
79
|
+
open( '/path/to/beepboop', 'r+', {}, done ); // $ExpectError
|
|
80
|
+
open( '/path/to/beepboop', 'r+', ( x: number ): number => x, done ); // $ExpectError
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// The compiler throws an error if the function is provided an unsupported number of arguments...
|
|
84
|
+
{
|
|
85
|
+
open(); // $ExpectError
|
|
86
|
+
open( 'C:\\foo\\bar\\baz' ); // $ExpectError
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Attached to main export is a `sync` method which returns a number or an error...
|
|
90
|
+
{
|
|
91
|
+
open.sync( '/path/to/beepboop' ); // $ExpectType number | Error
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// The compiler throws an error if the `sync` method is provided a first argument which is not a string...
|
|
95
|
+
{
|
|
96
|
+
open.sync( 123 ); // $ExpectError
|
|
97
|
+
open.sync( false ); // $ExpectError
|
|
98
|
+
open.sync( true ); // $ExpectError
|
|
99
|
+
open.sync( null ); // $ExpectError
|
|
100
|
+
open.sync( undefined ); // $ExpectError
|
|
101
|
+
open.sync( [] ); // $ExpectError
|
|
102
|
+
open.sync( {} ); // $ExpectError
|
|
103
|
+
open.sync( ( x: number ): number => x ); // $ExpectError
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// The compiler throws an error if the `sync` method is provided a second argument which is not a string or number...
|
|
107
|
+
{
|
|
108
|
+
open.sync( '/path/to/beepboop', false ); // $ExpectError
|
|
109
|
+
open.sync( '/path/to/beepboop', true ); // $ExpectError
|
|
110
|
+
open.sync( '/path/to/beepboop', null ); // $ExpectError
|
|
111
|
+
open.sync( '/path/to/beepboop', [] ); // $ExpectError
|
|
112
|
+
open.sync( '/path/to/beepboop', {} ); // $ExpectError
|
|
113
|
+
open.sync( '/path/to/beepboop', ( x: number ): number => x ); // $ExpectError
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// The compiler throws an error if the `sync` method is provided a third argument which is not a number...
|
|
117
|
+
{
|
|
118
|
+
open.sync( '/path/to/beepboop', 'r+', false ); // $ExpectError
|
|
119
|
+
open.sync( '/path/to/beepboop', 'r+', true ); // $ExpectError
|
|
120
|
+
open.sync( '/path/to/beepboop', 'r+', null ); // $ExpectError
|
|
121
|
+
open.sync( '/path/to/beepboop', 'r+', [] ); // $ExpectError
|
|
122
|
+
open.sync( '/path/to/beepboop', 'r+', {} ); // $ExpectError
|
|
123
|
+
open.sync( '/path/to/beepboop', 'r+', ( x: number ): number => x ); // $ExpectError
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// The compiler throws an error if the `sync` method is provided an unsupported number of arguments...
|
|
127
|
+
{
|
|
128
|
+
open.sync(); // $ExpectError
|
|
129
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
/**
|
|
22
|
+
* Open a file.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/fs/open
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var closeSync = require( '@stdlib/fs/close' ).sync;
|
|
28
|
+
* var open = require( '@stdlib/fs/open' );
|
|
29
|
+
*
|
|
30
|
+
* function onOpen( error, fd ) {
|
|
31
|
+
* if ( error ) {
|
|
32
|
+
* throw error;
|
|
33
|
+
* }
|
|
34
|
+
* closeSync( fd );
|
|
35
|
+
* }
|
|
36
|
+
* open( __filename, onOpen );
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* var closeSync = require( '@stdlib/fs/close' ).sync;
|
|
40
|
+
* var openSync = require( '@stdlib/fs/open' ).sync;
|
|
41
|
+
*
|
|
42
|
+
* var fd = openSync( __filename );
|
|
43
|
+
* if ( fd instanceof Error ) {
|
|
44
|
+
* throw fd;
|
|
45
|
+
* }
|
|
46
|
+
* closeSync( fd );
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
// MODULES //
|
|
50
|
+
|
|
51
|
+
var setReadOnly = require( '@ohos-ports/stdlib-utils/define-nonenumerable-read-only-property' );
|
|
52
|
+
var main = require( './main.js' );
|
|
53
|
+
var sync = require( './sync.js' );
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// MAIN //
|
|
57
|
+
|
|
58
|
+
setReadOnly( main, 'sync', sync );
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// EXPORTS //
|
|
62
|
+
|
|
63
|
+
module.exports = main;
|
package/open/lib/main.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
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 op = require( 'fs' ).open;
|
|
24
|
+
var defaults = require( './defaults.json' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// MAIN //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Asynchronously opens a file.
|
|
31
|
+
*
|
|
32
|
+
* @param {(string|Buffer)} path - file path
|
|
33
|
+
* @param {(string|number)} [flags='r'] - file system flags
|
|
34
|
+
* @param {integer} [mode=0o666] - file mode
|
|
35
|
+
* @param {Function} clbk - callback to invoke after opening a file
|
|
36
|
+
* @returns {void}
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* var closeSync = require( '@stdlib/fs/close' ).sync;
|
|
40
|
+
* var open = require( '@stdlib/fs/open' );
|
|
41
|
+
*
|
|
42
|
+
* function onOpen( error, fd ) {
|
|
43
|
+
* if ( error ) {
|
|
44
|
+
* throw error;
|
|
45
|
+
* }
|
|
46
|
+
* closeSync( fd );
|
|
47
|
+
* }
|
|
48
|
+
* open( __filename, onOpen );
|
|
49
|
+
*/
|
|
50
|
+
function open( path, flags, mode, clbk ) { // eslint-disable-line stdlib/no-redeclare
|
|
51
|
+
var nargs = arguments.length;
|
|
52
|
+
if ( nargs === 2 ) {
|
|
53
|
+
return op( path, defaults.flags, defaults.mode, flags );
|
|
54
|
+
}
|
|
55
|
+
if ( nargs === 3 ) {
|
|
56
|
+
return op( path, flags, defaults.mode, mode );
|
|
57
|
+
}
|
|
58
|
+
op( path, flags, mode, clbk );
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
// EXPORTS //
|
|
63
|
+
|
|
64
|
+
module.exports = open;
|
package/open/lib/sync.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
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 open = require( 'fs' ).openSync; // eslint-disable-line stdlib/no-redeclare
|
|
24
|
+
var defaults = require( './defaults.json' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// MAIN //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Synchronously opens a file.
|
|
31
|
+
*
|
|
32
|
+
* @param {(string|Buffer)} path - file path
|
|
33
|
+
* @param {(string|number)} [flags='r'] - file system flags
|
|
34
|
+
* @param {integer} [mode=0o666] - file mode
|
|
35
|
+
* @returns {(integer|Error)} file descriptor or an error
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var closeSync = require( '@stdlib/fs/close' ).sync;
|
|
39
|
+
*
|
|
40
|
+
* var fd = openSync( __filename );
|
|
41
|
+
* if ( fd instanceof Error ) {
|
|
42
|
+
* throw fd;
|
|
43
|
+
* }
|
|
44
|
+
* closeSync( fd );
|
|
45
|
+
*/
|
|
46
|
+
function openSync( path, flags, mode ) {
|
|
47
|
+
var nargs;
|
|
48
|
+
var fd;
|
|
49
|
+
|
|
50
|
+
nargs = arguments.length;
|
|
51
|
+
try {
|
|
52
|
+
if ( nargs === 1 ) {
|
|
53
|
+
fd = open( path, defaults.flags, defaults.mode );
|
|
54
|
+
} else if ( nargs === 2 ) {
|
|
55
|
+
fd = open( path, flags, defaults.mode );
|
|
56
|
+
} else {
|
|
57
|
+
fd = open( path, flags, mode );
|
|
58
|
+
}
|
|
59
|
+
} catch ( err ) {
|
|
60
|
+
return err;
|
|
61
|
+
}
|
|
62
|
+
return fd;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
// EXPORTS //
|
|
67
|
+
|
|
68
|
+
module.exports = openSync;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/fs/open",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Open 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
|
+
"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
|
+
"open",
|
|
56
|
+
"opensync",
|
|
57
|
+
"path",
|
|
58
|
+
"async",
|
|
59
|
+
"sync",
|
|
60
|
+
"file",
|
|
61
|
+
"read",
|
|
62
|
+
"filesystem"
|
|
63
|
+
]
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-ports/stdlib-fs",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.4.1-beta.0",
|
|
4
|
+
"description": "Filesystem APIs.",
|
|
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
|
+
"doc": "./docs",
|
|
19
|
+
"lib": "./lib"
|
|
20
|
+
},
|
|
21
|
+
"types": "./docs/types",
|
|
22
|
+
"scripts": {},
|
|
23
|
+
"homepage": "https://stdlib.io",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
27
|
+
"directory": "ports/stdlib-fs/0.4.1"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/ohos-ports/ohos-ports/issues"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@stdlib/array": "^0.5.0",
|
|
34
|
+
"@stdlib/assert": "^0.4.0",
|
|
35
|
+
"@stdlib/cli": "^0.4.0",
|
|
36
|
+
"@stdlib/math": "^0.4.0",
|
|
37
|
+
"@stdlib/object": "^0.4.0",
|
|
38
|
+
"@stdlib/process": "^0.4.0",
|
|
39
|
+
"@stdlib/string": "^0.4.0",
|
|
40
|
+
"@ohos-ports/stdlib-utils": "^0.4.1-beta.0",
|
|
41
|
+
"debug": "^2.6.9"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=0.10.0",
|
|
46
|
+
"npm": ">2.7.0"
|
|
47
|
+
},
|
|
48
|
+
"os": [
|
|
49
|
+
"aix",
|
|
50
|
+
"darwin",
|
|
51
|
+
"freebsd",
|
|
52
|
+
"linux",
|
|
53
|
+
"macos",
|
|
54
|
+
"openharmony",
|
|
55
|
+
"openbsd",
|
|
56
|
+
"sunos",
|
|
57
|
+
"win32",
|
|
58
|
+
"windows"
|
|
59
|
+
],
|
|
60
|
+
"keywords": [
|
|
61
|
+
"stdlib",
|
|
62
|
+
"standard",
|
|
63
|
+
"library",
|
|
64
|
+
"std",
|
|
65
|
+
"lib",
|
|
66
|
+
"fs",
|
|
67
|
+
"filesystem"
|
|
68
|
+
]
|
|
69
|
+
}
|