src/nodejs/jsfs

    Dark Mode
Search:
Group by:

Example:

import src/nodejs/jsfs
requireFs()
touchFileSync("touched.txt")
writeFileSync("touched.txt".cstring, "data".cstring)
appendFileSync("touched.txt".cstring, "\nmore data".cstring)
renameSync("touched.txt".cstring, "renamed.txt".cstring)
chmodSync("renamed.txt".cstring, 0o777)
copyFileSync("renamed.txt".cstring, "copied.txt".cstring)
let data: cstring = readFileSync("renamed.txt")
# Need to be commented out for Node 13 and older.
# rmSync("renamed.txt".cstring)
# rmSync("copied.txt".cstring)
echo mkdtempSync("test".cstring)
# mkdirSync("/tmp/somerandomame".cstring, recursive = true)

Example: cmd: -r:off

import src/nodejs/jsfs
import jsbuffer
requireFs()
requireBuffer()
proc example(error: int; data: Buffer) = echo data
readFile("somefile.ext", example)

Lets

F_OK: cint
O_APPEND: cint
O_CREAT: cint
O_DIRECT: cint
O_DIRECTORY: cint
O_DSYNC: cint
O_EXCL: cint
O_NOATIME: cint
O_NOCTTY: cint
O_NOFOLLOW: cint
O_NONBLOCK: cint
O_RDONLY: cint
O_RDWR: cint
O_SYNC: cint
O_TRUNC: cint
O_WRONLY: cint
R_OK: cint
S_IFBLK: cint
S_IFCHR: cint
S_IFDIR: cint
S_IFIFO: cint
S_IFLNK: cint
S_IFMT: cint
S_IFREG: cint
S_IFSOCK: cint
S_IRGRP: cint
S_IROTH: cint
S_IRUSR: cint
S_IRWXG: cint
S_IRWXO: cint
S_IRWXU: cint
S_IWGRP: cint
S_IWOTH: cint
S_IWUSR: cint
S_IXGRP: cint
S_IXOTH: cint
S_IXUSR: cint
W_OK: cint
X_OK: cint

Procs

func access[T](path: cstring; mode: cint; callback: T) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_access_path_mode_callback
func accessSync(path: cstring; mode: cint) {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_accesssync_path_mode
func appendFile[T](path, data: cstring; callback: T) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_appendfile_path_data_options_callback
func appendFileSync(path, data: cstring) {.importjs: "fs.$1(#, #)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_appendfilesync_path_data_options
func chmod[T](path: cstring; mode: cint; callback: T) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_chmod_path_mode_callback
func chmod[T](path: cstring; mode: cstring; callback: T) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_chmod_path_mode_callback
func chmodSync(path: cstring; mode: cint) {.importjs: "fs.$1(#, #)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_chmodsync_path_mode
func chmodSync(path: cstring; mode: cstring) {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_chmodsync_path_mode
func chown[T](path: cstring; uid: cint; gid: cint; callback: T) {.
    importjs: "fs.$1(#, #, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_chown_path_uid_gid_callback
func chownSync(path: cstring; uid: cint; gid: cint) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_chownsync_path_uid_gid
func close[T](fd: cint; callback: T) {.importjs: "fs.$1(#, #)", ...raises: [],
                                       tags: [].}
https://nodejs.org/api/fs.html#fs_fs_close_fd_callback
func closeSync(fd: cint) {.importjs: "fs.$1(#)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_closesync_fd
func copyFile[T](src, dest: cstring; callback: T) {.importjs: "fs.$1(#, #, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_copyfile_src_dest_mode_callback
func copyFile[T](src, dest: cstring; mode: cint; callback: T) {.
    importjs: "fs.$1(#, #, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_copyfile_src_dest_mode_callback
func copyFileSync(src, dest: cstring) {.importjs: "fs.$1(#, #)", ...raises: [],
                                        tags: [].}
https://nodejs.org/api/fs.html#fs_fs_copyfilesync_src_dest_mode
func copyFileSync(src, dest: cstring; mode: cint) {.importjs: "fs.$1(#, #, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_copyfilesync_src_dest_mode
func dirRead[T](path: cstring; callback: T) {.importjs: """  (() => { const d = fs.opendirSync(#); d.read(#); d.closeSync() })()""",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_dir_read_callback
func existsSync(path: cstring): bool {.importjs: "fs.$1(#)", ...raises: [],
                                       tags: [].}
https://nodejs.org/api/fs.html#fs_fs_existssync_path
func fchmod[T](fd: cint; mode: cint; callback: T) {.importjs: "fs.$1(#, #, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_fchmod_fd_mode_callback
func fchmod[T](fd: cint; mode: cstring; callback: T) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_fchmod_fd_mode_callback
func fchmodSync(fd: cint; mode: cint) {.importjs: "fs.$1(#, #)", ...raises: [],
                                        tags: [].}
https://nodejs.org/api/fs.html#fs_fs_fchmodsync_fd_mode
func fchmodSync(fd: cint; mode: cstring) {.importjs: "fs.$1(#, #)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_fchmodsync_fd_mode
func fchown[T](fd, uid, gid: cint; callback: T) {.importjs: "fs.$1(#, #, #, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_fchown_fd_uid_gid_callback
func fchownSync(fd, uid, gid: cint) {.importjs: "fs.$1(#, #, #)", ...raises: [],
                                      tags: [].}
https://nodejs.org/api/fs.html#fs_fs_fchownsync_fd_uid_gid
func fdatasync[T](fd: cint; callback: T) {.importjs: "fs.$1(#, #)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_fdatasync_fd_callback
func fdatasyncSync(fd: cint) {.importjs: "fs.$1(#)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_fdatasyncsync_fd
func fstat[T](fd: cint; callback: T) {.importjs: "fs.$1(#, #)", ...raises: [],
                                       tags: [].}
https://nodejs.org/api/fs.html#fs_fs_fstat_fd_options_callback
func fsync[T](fd: cint; callback: T) {.importjs: "fs.$1(#, #)", ...raises: [],
                                       tags: [].}
https://nodejs.org/api/fs.html#fs_fs_fsync_fd_callback
func ftruncate[T](fd: cint; callback: T) {.importjs: "fs.$1(#, #)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_ftruncate_fd_len_callback
func ftruncate[T](fd: cint; len: cint; callback: T) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_ftruncate_fd_len_callback
func ftruncateSync(fd: cint; len: cint) {.importjs: "fs.$1(#, #)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_ftruncatesync_fd_len
func futimes[T](fd: cint; atime: cint; mtime: cint; callback: T) {.
    importjs: "fs.$1(#, #, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_futimes_fd_atime_mtime_callback
func futimes[T](fd: cint; atime: cstring; mtime: cstring; callback: T) {.
    importjs: "fs.$1(#, #, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_futimes_fd_atime_mtime_callback
func futimesSync(fd: cint; atime: cint; mtime: cint) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_futimessync_fd_atime_mtime
func futimesSync(fd: cint; atime: cstring; mtime: cstring) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_futimessync_fd_atime_mtime
func importFs() {.importjs: "import * as fs from \'fs\'@", ...raises: [], tags: [].}
Alias for import * as module_name from 'module_name';. Must be called once before using the module
func lchown[T](path: cstring; uid: cint; gid: cint; callback: T) {.
    importjs: "fs.$1(#, #, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_lchown_path_uid_gid_callback
func lchownSync(path: cstring; uid: cint; gid: cint) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_lchownsync_path_uid_gid
func linkSync(existingPath: cstring; newPath: cstring) {.
    importjs: "fs.$1(#, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_linksync_existingpath_newpath
func lstat[T](path: cstring; callback: T) {.importjs: "fs.$1(#, #)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_lstat_path_options_callback
func lutimes[T](path: cstring; atime: cint; mtime: cint; callback: T) {.
    importjs: "fs.$1(#, #, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_lutimes_path_atime_mtime_callback
func lutimes[T](path: cstring; atime: cstring; mtime: cstring; callback: T) {.
    importjs: "fs.$1(#, #, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_lutimes_path_atime_mtime_callback
func lutimesSync(path: cstring; atime: cint; mtime: cint) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_lutimessync_path_atime_mtime
func lutimesSync(path: cstring; atime: cstring; mtime: cstring) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_lutimessync_path_atime_mtime
func mkdir[T](path: cstring; callback: T) {.importjs: "fs.$1(#, #)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback
func mkdirSync(path: cstring; recursive = false) {.
    importjs: "fs.$1(#, {recursive: #})", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_mkdirsync_path_options
func mkdtemp[T](prefix: cstring; callback: T) {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_mkdtemp_prefix_options_callback
func mkdtempSync(prefix: cstring): cstring {.importjs: "fs.$1(#)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_mkdtempsync_prefix_options
func open[T](path: cstring; callback: T) {.importjs: "fs.$1(#, #)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback
func open[T](path: cstring; flags: cint; mode: cint; callback: T) {.
    importjs: "fs.$1(#, #, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback
func open[T](path: cstring; flags: cstring; mode: cstring; callback: T) {.
    importjs: "fs.$1(#, #, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback
func opendir[T](path: cstring; callback: T) {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_opendir_path_options_callback
func openSync(path: cstring; flags: cint; mode: cint): cint {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_opensync_path_flags_mode
func openSync(path: cstring; flags: cstring; mode: cstring): cint {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_opensync_path_flags_mode
func read[T](fd: cint; callback: T) {.importjs: "fs.$1(#, #)", ...raises: [],
                                      tags: [].}
https://nodejs.org/api/fs.html#fs_fs_read_fd_options_callback
func readdir[T](path: cstring; callback: T) {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback
func readFile[T](path: cstring; callback: T) {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback
func readFileSync(path: cstring): cstring {.importjs: "fs.$1(#).toString()",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_readfilesync_path_options
func readlinkSync(path: cstring): cstring {.importjs: "fs.$1(#)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_readlinksync_path_options
func realpath[T](path: cstring; callback: T) {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_realpath_path_options_callback
func realpathNative[T](path: cstring; callback: T) {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_realpath_native_path_options_callback
func realpathSync(path: cstring): cstring {.importjs: "fs.$1(#)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_realpathsync_path_options
func realpathSyncNative(path: cstring): cstring {.importjs: "fs.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_realpathsync_native_path_options
func rename[T](oldPath, newPath: cstring; callback: T) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback
func renameSync(oldPath, newPath: cstring) {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_renamesync_oldpath_newpath
func requireFs() {.importjs: "const fs = require(\'fs\')@", ...raises: [], tags: [].}
Alias for const module_name = require('module_name');. Must be called once before using the module
func rm[T](path: cstring; callback: T) {.importjs: "fs.$1(#, #)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_rm_path_options_callback
func rmdir(path: cstring) {.importjs: "fs.$1(#)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_rmdirsync_path_options
func rmdir[T](path: cstring; callback: T) {.importjs: "fs.$1(#, #)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_rmdir_path_options_callback
func rmSync(path: cstring) {.importjs: "fs.$1(#)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_rmsync_path_options
func stat[T](path: cstring; callback: T) {.importjs: "fs.$1(#, #)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_stat_path_options_callback
func symlinkSync(target, path, tipe: cstring) {.importjs: "fs.$1(#, #, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_symlinksync_target_path_type
func symlinkSync(target, path: cstring) {.importjs: "fs.$1(#, #)", ...raises: [],
    tags: [].}
https://nodejs.org/api/fs.html#fs_fs_symlinksync_target_path_type
func touchFileSync(filename: cstring) {.importjs: """  (() => {
    const path = #;
    const time = new Date();
    try {
      fs.utimesSync(path, time, time);
    } catch(err) {
      fs.closeSync(fs.openSync(path, 'w'));
    }
  })()""",
                                        ...raises: [], tags: [].}
Convenience func to touch a file.
func truncate[T](path: cstring; callback: T) {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_truncate_path_len_callback
func truncate[T](path: cstring; len: cint; callback: T) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_truncate_path_len_callback
func truncateSync(path: cstring; len: cint) {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_truncatesync_path_len
func unlinkSync(path: cstring) {.importjs: "fs.$1(#)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_unlinksync_path
func unwatchFile(filename: cstring) {.importjs: "fs.$1(#)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_unwatchfile_filename_listener
func unwatchFile[T](fd: cint; stryng: cstring; callback: T) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_write_fd_string_position_encoding_callback
func unwatchFile[T](fd: cint; stryng: cstring; position: cint; callback: T) {.
    importjs: "fs.$1(#, #, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_write_fd_string_position_encoding_callback
func unwatchFile[T](filename: cstring; listener: T) {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_unwatchfile_filename_listener
func utimes[T](path: cstring; atime: cint; mtime: cint; callback: T) {.
    importjs: "fs.$1(#, #, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_utimes_path_atime_mtime_callback
func utimes[T](path: cstring; atime: cstring; mtime: cstring; callback: T) {.
    importjs: "fs.$1(#, #, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_utimes_path_atime_mtime_callback
func utimesSync(path: cstring; atime: cint; mtime: cint) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_utimes_path_atime_mtime_callback
func utimesSync(path: cstring; atime: cstring; mtime: cstring) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_utimes_path_atime_mtime_callback
func watch[T](filename: cstring; listener: T) {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener
func writeFile[T](fd: cint; data: cstring; callback: T) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback
func writeFile[T](fd: cstring; data: cstring; callback: T) {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
func writeFileSync(file: cint; data: cstring) {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options
func writeFileSync(file: cstring; data: cstring) {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options
func writeSync(fd: cint; buffer: cstring): cint {.importjs: "fs.$1(#, #)",
    ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_writesync_fd_buffer_offset_length_position
func writeSync(fd: cint; buffer: cstring; offset: cint): cint {.
    importjs: "fs.$1(#, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_writesync_fd_buffer_offset_length_position
func writeSync(fd: cint; buffer: cstring; offset: cint; length: cint): cint {.
    importjs: "fs.$1(#, #, #, #)", ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_writesync_fd_buffer_offset_length_position
func writeSync(fd: cint; buffer: cstring; offset: cint; length: cint;
               position: cint): cint {.importjs: "fs.$1(#, #, #, #, #)",
                                       ...raises: [], tags: [].}
https://nodejs.org/api/fs.html#fs_fs_writesync_fd_buffer_offset_length_position

Templates

template withDir(dir: cstring; body: untyped): untyped
Same as Fusion withDir but for NodeJS, uses __dirname.