1616* limitations under the License.
1717*/
1818
19- /* tslint:disable:completed-docs */
20-
2119// TypeScript Version: 2.0
2220
2321import close = require( '@stdlib/fs/close' ) ;
@@ -32,20 +30,332 @@ import rename = require( '@stdlib/fs/rename' );
3230import resolveParentPath = require( '@stdlib/fs/resolve-parent-path' ) ;
3331import unlink = require( '@stdlib/fs/unlink' ) ;
3432
33+ /**
34+ * Interface describing the `fs` namespace.
35+ */
3536interface FS {
37+ /**
38+ * Asynchronously closes a file descriptor.
39+ *
40+ * @param fd - file descriptor
41+ * @param clbk - callback to invoke after closing a file descriptor
42+ * @throws first argument must be a valid file descriptor (nonnegative integer)
43+ *
44+ * @example
45+ * var openSync = require( `@stdlib/fs/open` ).sync;
46+ *
47+ * function done( error ) {
48+ * if ( error ) {
49+ * throw error;
50+ * }
51+ * }
52+ *
53+ * var fd = openSync( __filename, 'r+' );
54+ * if ( fd instanceof Error ) {
55+ * throw fd;
56+ * }
57+ *
58+ * close( fd, done );
59+ *
60+ * @example
61+ * var openSync = require( `@stdlib/fs/open` ).sync;
62+ *
63+ * var fd = openSync( __filename, 'r+' );
64+ *
65+ * if ( fd instanceof Error ) {
66+ * throw fd;
67+ * }
68+ *
69+ * var err = close.sync( fd );
70+ * if ( err instanceof Error ) {
71+ * throw err;
72+ * }
73+ */
3674 close : typeof close ;
75+
76+ /**
77+ * Tests whether a path exists on the filesystem.
78+ *
79+ * @param path - path to test
80+ * @param clbk - callback to invoke after testing path existence
81+ *
82+ * @example
83+ * exists( __dirname, done );
84+ *
85+ * function done( error, bool ) {
86+ * if ( error ) {
87+ * console.error( error );
88+ * }
89+ * if ( bool ) {
90+ * console.log( '...path exists.' );
91+ * } else {
92+ * console.log( '...path does not exist.' );
93+ * }
94+ * }
95+ *
96+ * @example
97+ * var bool = exists.sync( __dirname );
98+ * // returns <boolean>
99+ */
37100 exists : typeof exists ;
101+
102+ /**
103+ * Asynchronously opens a file.
104+ *
105+ * @param path - file path
106+ * @param flags - file system flags (default: 'r')
107+ * @param mode - file mode (default: 0o666)
108+ * @param clbk - callback to invoke after opening a file
109+ *
110+ * @example
111+ * var closeSync = require( `@stdlib/fs/close` ).sync;
112+ *
113+ * function onOpen( error, fd ) {
114+ * if ( error ) {
115+ * throw error;
116+ * }
117+ * closeSync( fd );
118+ * }
119+ * open( __filename, onOpen );
120+ *
121+ * @example
122+ * var closeSync = require( `@stdlib/fs/close` ).sync;
123+ *
124+ * var fd = open.sync( __filename );
125+ * if ( fd instanceof Error ) {
126+ * throw fd;
127+ * }
128+ * closeSync( fd );
129+ */
38130 open : typeof open ;
131+
132+ /**
133+ * Asynchronously reads the contents of a directory.
134+ *
135+ * @param path - directory path
136+ * @param clbk - callback to invoke after reading directory contents
137+ *
138+ * @example
139+ * function onRead( error, data ) {
140+ * if ( error ) {
141+ * console.error( error );
142+ * } else {
143+ * console.log( data );
144+ * }
145+ * }
146+ * readDir( __dirname, onRead );
147+ *
148+ * @example
149+ * var out = readDir.sync( __dirname );
150+ * if ( out instanceof Error ) {
151+ * throw out;
152+ * }
153+ * console.log( out );
154+ */
39155 readDir : typeof readDir ;
156+
157+ /**
158+ * Asynchronously reads the entire contents of a file.
159+ *
160+ * @param file - file path or file descriptor
161+ * @param options - options
162+ * @param options.encoding - file encoding
163+ * @param options.flag - file status flag
164+ * @param clbk - callback to invoke after reading file contents
165+ *
166+ * @example
167+ * function onFile( error, data ) {
168+ * if ( error ) {
169+ * throw error;
170+ * }
171+ * console.log( data );
172+ * }
173+ * readFile( __filename, onFile );
174+ *
175+ * @example
176+ * var out = readFile.sync( __filename );
177+ * if ( out instanceof Error ) {
178+ * throw out;
179+ * }
180+ * console.log( out );
181+ */
40182 readFile : typeof readFile ;
183+
184+ /**
185+ * Asynchronously reads the entire contents of each file in a file list.
186+ *
187+ * @param list - list of file paths
188+ * @param options - options
189+ * @param options.encoding - file encoding
190+ * @param options.flag - file status flag
191+ * @param clbk - callback to invoke after reading file contents
192+ *
193+ * @example
194+ * var list = [ __filename ];
195+ *
196+ * readFileList( list, onFiles );
197+ *
198+ * function onFiles( error, files ) {
199+ * if ( error ) {
200+ * throw error;
201+ * }
202+ * console.dir( files );
203+ * }
204+ *
205+ * @example
206+ * var list = [ __filename ];
207+ * var files = readFileList.sync( list );
208+ *
209+ * if ( files instanceof Error ) {
210+ * throw files;
211+ * }
212+ * console.dir( files );
213+ */
41214 readFileList : typeof readFileList ;
215+
216+ /**
217+ * Asynchronously reads a file as JSON.
218+ *
219+ * @param file - file path or file descriptor
220+ * @param options - options
221+ * @param options.encoding - file encoding
222+ * @param options.flag - file status flag
223+ * @param options.reviver - JSON reviver
224+ * @param clbk - callback
225+ *
226+ * @example
227+ * var resolve = require( `path` ).resolve;
228+ *
229+ * readJSON( resolve( __dirname, '..', 'package.json' ), 'utf-8', onJSON );
230+ *
231+ * function onJSON( error, data ) {
232+ * if ( error ) {
233+ * throw error;
234+ * }
235+ * console.dir( data );
236+ * }
237+ *
238+ * @example
239+ * var resolve = require( `path` ).resolve;
240+ * var instanceOf = require( `@stdlib/assert/instance-of` );
241+ *
242+ * var out = readJSON.sync( resolve( __dirname, '..', 'package.json' ) );
243+ * if ( instanceOf( out, Error ) ) {
244+ * throw out;
245+ * }
246+ * console.dir( out );
247+ */
42248 readJSON : typeof readJSON ;
249+
250+ /**
251+ * Reads the entire contents of a WebAssembly file.
252+ *
253+ * @param file - file path or file descriptor
254+ * @param options - options
255+ * @param options.flag - file status flag
256+ * @param clbk - callback to invoke after reading a file
257+ *
258+ * @example
259+ * var join = require( `path` ).join;
260+ * var instanceOf = require( `@stdlib/assert/instance-of` );
261+ *
262+ * var fpath = join( __dirname, 'foo.wasm' );
263+ * readWASM( fpath, onRead );
264+ *
265+ * function onRead( error, buf ) {
266+ * if ( error ) {
267+ * throw error;
268+ * }
269+ * console.log( buf );
270+ * }
271+ *
272+ * @example
273+ * var join = require( `path` ).join;
274+ * var instanceOf = require( `@stdlib/assert/instance-of` );
275+ *
276+ * var fpath = join( __dirname, 'foo.wasm' );
277+ * var out = readWASM.sync( fpath );
278+ * if ( instanceOf( out, Error ) ) {
279+ * throw out;
280+ * }
281+ * console.log( out );
282+ */
43283 readWASM : typeof readWASM ;
284+
285+ /**
286+ * Asynchronously renames a file.
287+ *
288+ * @param oldPath - old path
289+ * @param newPath - new path
290+ * @param clbk - callback to invoke after renaming a path
291+ *
292+ * @example
293+ * function done( error ) {
294+ * if ( error ) {
295+ * throw error;
296+ * }
297+ * }
298+ *
299+ * rename( './beep/boop.txt', './beep/foo.txt', done );
300+ *
301+ * @example
302+ * var err = rename.sync( './beep/boop.txt', './beep/foo.txt' );
303+ * if ( err instanceof Error ) {
304+ * throw err;
305+ * }
306+ */
44307 rename : typeof rename ;
308+
309+ /**
310+ * Asynchronously resolves a path by walking parent directories.
311+ *
312+ * @param path - path to resolve
313+ * @param options - function options
314+ * @param options.dir - base directory
315+ * @param clbk - callback to invoke after resolving a path
316+ * @throws must provide valid options
317+ *
318+ * @example
319+ * resolveParentPath( 'package.json', onPath );
320+ *
321+ * function onPath( error, path ) {
322+ * if ( error ) {
323+ * throw error;
324+ * }
325+ * console.log( path );
326+ * }
327+ *
328+ * @example
329+ * var path = resolveParentPath.sync( 'package.json' );
330+ */
45331 resolveParentPath : typeof resolveParentPath ;
332+
333+ /**
334+ * Asynchronously removes a directory entry.
335+ *
336+ * @param path - entry path
337+ * @param clbk - callback to invoke after removing a directory entry
338+ *
339+ * @example
340+ * function done( error ) {
341+ * if ( error ) {
342+ * throw error;
343+ * }
344+ * }
345+ * unlink( './beep/boop.txt', done );
346+ *
347+ * @example
348+ * var err = unlink.sync( './beep/boop.txt' );
349+ * if ( err instanceof Error ) {
350+ * throw err;
351+ * }
352+ */
46353 unlink : typeof unlink ;
47354}
48355
356+ /**
357+ * Standard library for interfacing with a fileystem.
358+ */
49359declare var fs : FS ;
50360
51361
0 commit comments