0.6.0-rc.8 • Published 9 months ago

@socketsupply/socket v0.6.0-rc.8

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
9 months ago

Buffer

Buffer module is a third party vendor module provided by Feross Aboukhadijeh and other contributors (MIT License).

External docs: https://nodejs.org/api/buffer.html

Events

Events module is a third party module provided by Browserify and Node.js contributors (MIT License).

External docs: https://nodejs.org/api/events.html

application

Provides Application level methods

Example usage:

import { createWindow } from 'socket:application'

MAX_WINDOWS

This is a VariableDeclaration named MAX_WINDOWS in api/application.js, it's exported but undocumented.

ApplicationWindowList

This is a ClassDeclaration named ApplicationWindowList in api/application.js, it's exported but undocumented.

addEventListener(type, listener, |boolean)

Add an application event type callback listener with options.

ArgumentTypeDefaultOptionalDescription
typestringfalse
listenerfunction(Event | MessageEvent | CustomEvent | ApplicationURLEvent): booleanfalse
boolean{ once?: boolean} optionsfalse

removeEventListener(type, listener)

Remove an application event type callback listener with options.

ArgumentTypeDefaultOptionalDescription
typestringfalse
listenerfunction(Event | MessageEvent | CustomEvent | ApplicationURLEvent): booleanfalse

getCurrentWindowIndex()

Returns the current window index

Return ValueTypeDescription
Not specifiednumber

createWindow(opts)

Creates a new window and returns an instance of ApplicationWindow.

ArgumentTypeDefaultOptionalDescription
optsobjectfalsean options object
opts.aspectRatiostringtruea string (split on ':') provides two float values which set the window's aspect ratio.
opts.closablebooleantruedeterime if the window can be closed.
opts.minimizablebooleantruedeterime if the window can be minimized.
opts.maximizablebooleantruedeterime if the window can be maximized.
opts.marginnumbertruea margin around the webview. (Private)
opts.radiusnumbertruea radius on the webview. (Private)
opts.indexnumberfalsethe index of the window.
opts.pathstringfalsethe path to the HTML file to load into the window.
opts.titlestringtruethe title of the window.
opts.titlebarStylestringtruedetermines the style of the titlebar (MacOS only).
opts.windowControlOffsetsstringtruea string (split on 'x') provides the x and y position of the traffic lights (MacOS only).
opts.backgroundColorDarkstringtruedetermines the background color of the window in dark mode.
opts.backgroundColorLightstringtruedetermines the background color of the window in light mode.
opts.widthnumber | stringtruethe width of the window. If undefined, the window will have the main window width.
opts.heightnumber | stringtruethe height of the window. If undefined, the window will have the main window height.
opts.minWidthnumber | string0truethe minimum width of the window
opts.minHeightnumber | string0truethe minimum height of the window
opts.maxWidthnumber | string100%truethe maximum width of the window
opts.maxHeightnumber | string100%truethe maximum height of the window
opts.resizablebooleantruetruewhether the window is resizable
opts.framelessbooleanfalsetruewhether the window is frameless
opts.utilitybooleanfalsetruewhether the window is utility (macOS only)
opts.shouldExitApplicationOnClosebooleanfalsetruewhether the window can exit the app
opts.headlessbooleanfalsetruewhether the window will be headless or not (no frame)
opts.userScriptstringnulltrueA user script that will be injected into the window (desktop only)
opts.protocolHandlersstringtrueAn array of protocol handler schemes to register with the new window (requires service worker)
Return ValueTypeDescription
Not specifiedPromise

radius()

margin()

getScreenSize()

Returns the current screen size.

Return ValueTypeDescription
Not specifiedPromise<{ width: number, height: number>}

getWindows(indices)

Returns the ApplicationWindow instances for the given indices or all windows if no indices are provided.

ArgumentTypeDefaultOptionalDescription
indicesnumbertruethe indices of the windows
Return ValueTypeDescription
Not specifiedPromise

getWindow(index)

Returns the ApplicationWindow instance for the given index

ArgumentTypeDefaultOptionalDescription
indexnumberfalsethe index of the window
Return ValueTypeDescription
Not specifiedPromisethe ApplicationWindow instance or null if the window does not exist

getCurrentWindow()

Returns the ApplicationWindow instance for the current window.

Return ValueTypeDescription
Not specifiedPromise

exit(code)

Quits the backend process and then quits the render process, the exit code used is the final exit code to the OS.

ArgumentTypeDefaultOptionalDescription
codenumber0truean exit code
Return ValueTypeDescription
Not specifiedPromise<ipc.Result>

setSystemMenu(options)

Set the native menu for the app.

Socket Runtime provides a minimalist DSL that makes it easy to create cross platform native system and context menus.

Menus are created at run time. They can be created from either the Main or Render process. The can be recreated instantly by calling the setSystemMenu method.

The method takes a string. Here's an example of a menu. The semi colon is significant indicates the end of the menu. Use an underscore when there is no accelerator key. Modifiers are optional. And well known OS menu options like the edit menu will automatically get accelerators you dont need to specify them.

socket.application.setSystemMenu({ index: 0, value: `
  App:
    Foo: f;

  Edit:
    Cut: x
    Copy: c
    Paste: v
    Delete: _
    Select All: a;

  Other:
    Apple: _
    Another Test: T
    !Im Disabled: I
    Some Thing: S + Meta
    ---
    Bazz: s + Meta, Control, Alt;
`)

Separators

To create a separator, use three dashes ---.

Accelerator Modifiers

Accelerator modifiers are used as visual indicators but don't have a material impact as the actual key binding is done in the event listener.

A capital letter implies that the accelerator is modified by the Shift key.

Additional accelerators are Meta, Control, Option, each separated by commas. If one is not applicable for a platform, it will just be ignored.

On MacOS Meta is the same as Command.

Disabled Items

If you want to disable a menu item just prefix the item with the ! character. This will cause the item to appear disabled when the system menu renders.

Submenus

We feel like nested menus are an anti-pattern. We don't use them. If you have a strong argument for them and a very simple pull request that makes them work we may consider them.

Event Handling

When a menu item is activated, it raises the menuItemSelected event in the front end code, you can then communicate with your backend code if you want from there.

For example, if the Apple item is selected from the Other menu...

window.addEventListener('menuItemSelected', event => {
  assert(event.detail.parent === 'Other')
  assert(event.detail.title === 'Apple')
})
ArgumentTypeDefaultOptionalDescription
optionsobjectfalsean options object
options.valuestringfalsethe menu layout
options.indexnumberfalsethe window to target (if applicable)
Return ValueTypeDescription
Not specifiedPromise<ipc.Result>

setTrayMenu()

An alias to setSystemMenu for creating a tary menu

setSystemMenuItemEnabled(value)

Set the enabled state of the system menu.

ArgumentTypeDefaultOptionalDescription
valueobjectfalsean options object
Return ValueTypeDescription
Not specifiedPromise<ipc.Result>

isPaused()

Predicate function to determine if application is in a "paused" state.

Return ValueTypeDescription
Not specifiedboolean

runtimeVersion

Socket Runtime version.

debug

Runtime debug flag.

config

Application configuration.

backend

The application's backend instance.

open(opts)

ArgumentTypeDefaultOptionalDescription
optsobjectfalsean options object
opts.forcebooleanfalsetruewhether to force the existing process to close
Return ValueTypeDescription
Not specifiedPromise<ipc.Result>

close()

Return ValueTypeDescription
Not specifiedPromise<ipc.Result>

bluetooth

A high-level, cross-platform API for Bluetooth Pub-Sub

Example usage:

import { Bluetooth } from 'socket:bluetooth'

Bluetooth (extends EventEmitter)

Create an instance of a Bluetooth service.

constructor(serviceId)

constructor is an example property that is set to true Creates a new service with key-value pairs

ArgumentTypeDefaultOptionalDescription
serviceIdstringfalseGiven a default value to determine the type

start()

Start the Bluetooth service.

Return ValueTypeDescription
Not specifiedPromise<ipc.Result>

subscribe(id)

Start scanning for published values that correspond to a well-known UUID. Once subscribed to a UUID, events that correspond to that UUID will be emitted. To receive these events you can add an event listener, for example...

const ble = new Bluetooth(id)
ble.subscribe(uuid)
ble.on(uuid, (data, details) => {
  // ...do something interesting
})
ArgumentTypeDefaultOptionalDescription
idstringtrueA well-known UUID
Return ValueTypeDescription
Not specifiedPromise<ipc.Result>

publish(id, value)

Start advertising a new value for a well-known UUID

ArgumentTypeDefaultOptionalDescription
idstringtrueA well-known UUID
valuestringtrue
Return ValueTypeDescription
Not specifiedPromise

crypto

Some high-level methods around the crypto.subtle API for getting random bytes and hashing.

Example usage:

import { randomBytes } from 'socket:crypto'

webcrypto

External docs: https://developer.mozilla.org/en-US/docs/Web/API/Crypto WebCrypto API

ready

A promise that resolves when all internals to be loaded/ready.

getRandomValues(buffer)

External docs: https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues Generate cryptographically strong random values into the buffer

ArgumentTypeDefaultOptionalDescription
bufferTypedArrayfalse
Return ValueTypeDescription
Not specifiedTypedArray

rand64()

Generate a random 64-bit number.

Return ValueTypeDescription
A random 64-bit number.BigInt

RANDOM_BYTES_QUOTA

Maximum total size of random bytes per page

MAX_RANDOM_BYTES

Maximum total size for random bytes.

MAX_RANDOM_BYTES_PAGES

Maximum total amount of allocated per page of bytes (max/quota)

randomBytes(size)

Generate size random bytes.

ArgumentTypeDefaultOptionalDescription
sizenumberfalseThe number of bytes to generate. The size must not be larger than 2**31 - 1.
Return ValueTypeDescription
Not specifiedBufferA promise that resolves with an instance of socket.Buffer with random bytes.

createDigest(algorithm, message)

ArgumentTypeDefaultOptionalDescription
algorithmstringfalseSHA-1SHA-256SHA-384SHA-512
messageBuffer | TypedArray | DataViewfalseAn instance of socket.Buffer, TypedArray or Dataview.
Return ValueTypeDescription
Not specifiedPromiseA promise that resolves with an instance of socket.Buffer with the hash.

murmur3(value, seed)

A murmur3 hash implementation based on https://github.com/jwerle/murmurhash.c that works on strings and ArrayBuffer views (typed arrays)

ArgumentTypeDefaultOptionalDescription
valuestring | Uint8Array | ArrayBufferfalse
seednumber0true
Return ValueTypeDescription
Not specifiednumber

dgram

This module provides an implementation of UDP datagram sockets. It does not (yet) provide any of the multicast methods or properties.

Example usage:

import { createSocket } from 'socket:dgram'

createSocket(options, callback)

Creates a Socket instance.

ArgumentTypeDefaultOptionalDescription
optionsstring | Objectfalseeither a string ('udp4' or 'udp6') or an options object
options.typestringtrueThe family of socket. Must be either 'udp4' or 'udp6'. Required.
options.reuseAddrbooleanfalsetrueWhen true socket.bind() will reuse the address, even if another process has already bound a socket on it. Default: false.
options.ipv6OnlybooleanfalsetrueDefault: false.
options.recvBufferSizenumbertrueSets the SO_RCVBUF socket value.
options.sendBufferSizenumbertrueSets the SO_SNDBUF socket value.
options.signalAbortSignaltrueAn AbortSignal that may be used to close a socket.
callbackfunctiontrueAttached as a listener for 'message' events. Optional.
Return ValueTypeDescription
Not specifiedSocket

Socket (extends EventEmitter)

New instances of dgram.Socket are created using dgram.createSocket(). The new keyword is not to be used to create dgram.Socket instances.

bind(port, address, callback)

External docs: https://nodejs.org/api/dgram.html#socketbindport-address-callback Listen for datagram messages on a named port and optional address If the address is not specified, the operating system will attempt to listen on all addresses. Once the binding is complete, a 'listening' event is emitted and the optional callback function is called.

If binding fails, an 'error' event is emitted.

ArgumentTypeDefaultOptionalDescription
portnumberfalseThe port to listen for messages on
addressstringfalseThe address to bind to (0.0.0.0)
callbackfunctionfalseWith no parameters. Called when binding is complete.

connect(port, host, connectListener)

External docs: https://nodejs.org/api/dgram.html#socketconnectport-address-callback Associates the dgram.Socket to a remote address and port. Every message sent by this handle is automatically sent to that destination. Also, the socket will only receive messages from that remote peer. Trying to call connect() on an already connected socket will result in an ERR_SOCKET_DGRAM_IS_CONNECTED exception. If the address is not provided, '0.0.0.0' (for udp4 sockets) or '::1' (for udp6 sockets) will be used by default. Once the connection is complete, a 'connect' event is emitted and the optional callback function is called. In case of failure, the callback is called or, failing this, an 'error' event is emitted.

ArgumentTypeDefaultOptionalDescription
portnumberfalsePort the client should connect to.
hoststringtrueHost the client should connect to.
connectListenerfunctiontrueCommon parameter of socket.connect() methods. Will be added as a listener for the 'connect' event once.

disconnect()

External docs: https://nodejs.org/api/dgram.html#socketdisconnect A synchronous function that disassociates a connected dgram.Socket from its remote address. Trying to call disconnect() on an unbound or already disconnected socket will result in an ERR_SOCKET_DGRAM_NOT_CONNECTED exception.

send(msg, offset, length, port, address, callback)

External docs: https://nodejs.org/api/dgram.html#socketsendmsg-offset-length-port-address-callback Broadcasts a datagram on the socket. For connectionless sockets, the destination port and address must be specified. Connected sockets, on the other hand, will use their associated remote endpoint, so the port and address arguments must not be set.

The msg argument contains the message to be sent. Depending on its type, different behavior can apply. If msg is a Buffer, any TypedArray, or a DataView, the offset and length specify the offset within the Buffer where the message begins and the number of bytes in the message, respectively. If msg is a String, then it is automatically converted to a Buffer with 'utf8' encoding. With messages that contain multi-byte characters, offset, and length will be calculated with respect to byte length and not the character position. If msg is an array, offset and length must not be specified.

The address argument is a string. If the value of the address is a hostname, DNS will be used to resolve the address of the host. If the address is not provided or otherwise nullish, '0.0.0.0' (for udp4 sockets) or '::1' (for udp6 sockets) will be used by default.

If the socket has not been previously bound with a call to bind, the socket is assigned a random port number and is bound to the "all interfaces" address ('0.0.0.0' for udp4 sockets, '::1' for udp6 sockets.)

An optional callback function may be specified as a way of reporting DNS errors or for determining when it is safe to reuse the buf object. DNS lookups delay the time to send for at least one tick of the Node.js event loop.

The only way to know for sure that the datagram has been sent is by using a callback. If an error occurs and a callback is given, the error will be passed as the first argument to the callback. If a callback is not given, the error is emitted as an 'error' event on the socket object.

Offset and length are optional but both must be set if either is used. They are supported only when the first argument is a Buffer, a TypedArray, or a DataView.

ArgumentTypeDefaultOptionalDescription
msgBuffer | TypedArray | DataView | string | ArrayfalseMessage to be sent.
offsetintegertrueOffset in the buffer where the message starts.
lengthintegertrueNumber of bytes in the message.
portintegertrueDestination port.
addressstringtrueDestination host name or IP address.
callbackFunctiontrueCalled when the message has been sent.

close(callback)

External docs: https://nodejs.org/api/dgram.html#socketclosecallback Close the underlying socket and stop listening for data on it. If a callback is provided, it is added as a listener for the 'close' event.

ArgumentTypeDefaultOptionalDescription
callbackfunctiontrueCalled when the connection is completed or on error.

address()

External docs: https://nodejs.org/api/dgram.html#socketaddress Returns an object containing the address information for a socket. For UDP sockets, this object will contain address, family, and port properties.

This method throws EBADF if called on an unbound socket.

Return ValueTypeDescription
socketInfoObjectInformation about the local socket
socketInfo.addressstringThe IP address of the socket
socketInfo.portstringThe port of the socket
socketInfo.familystringThe IP family of the socket

remoteAddress()

External docs: https://nodejs.org/api/dgram.html#socketremoteaddress Returns an object containing the address, family, and port of the remote endpoint. This method throws an ERR_SOCKET_DGRAM_NOT_CONNECTED exception if the socket is not connected.

Return ValueTypeDescription
socketInfoObjectInformation about the remote socket
socketInfo.addressstringThe IP address of the socket
socketInfo.portstringThe port of the socket
socketInfo.familystringThe IP family of the socket

setRecvBufferSize(size)

External docs: https://nodejs.org/api/dgram.html#socketsetrecvbuffersizesize Sets the SO_RCVBUF socket option. Sets the maximum socket receive buffer in bytes.

ArgumentTypeDefaultOptionalDescription
sizenumberfalseThe size of the new receive buffer

setSendBufferSize(size)

External docs: https://nodejs.org/api/dgram.html#socketsetsendbuffersizesize Sets the SO_SNDBUF socket option. Sets the maximum socket send buffer in bytes.

ArgumentTypeDefaultOptionalDescription
sizenumberfalseThe size of the new send buffer

getRecvBufferSize()

External docs: https://nodejs.org/api/dgram.html#socketgetrecvbuffersize

getSendBufferSize()

External docs: https://nodejs.org/api/dgram.html#socketgetsendbuffersize

Return ValueTypeDescription
Not specifiednumberthe SO_SNDBUF socket send buffer size in bytes.

code()

ERR_SOCKET_ALREADY_BOUND (extends SocketError)

Thrown when a socket is already bound.

ERR_SOCKET_DGRAM_IS_CONNECTED (extends SocketError)

Thrown when the socket is already connected.

ERR_SOCKET_DGRAM_NOT_CONNECTED (extends SocketError)

Thrown when the socket is not connected.

ERR_SOCKET_DGRAM_NOT_RUNNING (extends SocketError)

Thrown when the socket is not running (not bound or connected).

ERR_SOCKET_BAD_TYPE (extends TypeError)

Thrown when a bad socket type is used in an argument.

ERR_SOCKET_BAD_PORT (extends RangeError)

Thrown when a bad port is given.

dns

This module enables name resolution. For example, use it to look up IP addresses of host names. Although named for the Domain Name System (DNS), it does not always use the DNS protocol for lookups. dns.lookup() uses the operating system facilities to perform name resolution. It may not need to perform any network communication. To perform name resolution the way other applications on the same system do, use dns.lookup().

Example usage:

import { lookup } from 'socket:dns'

lookup(hostname, options, cb)

External docs: https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback Resolves a host name (e.g. example.org) into the first found A (IPv4) or AAAA (IPv6) record. All option properties are optional. If options is an integer, then it must be 4 or 6 – if options is 0 or not provided, then IPv4 and IPv6 addresses are both returned if found.

From the node.js website...

With the all option set to true, the arguments for callback change to (err, addresses), with addresses being an array of objects with the properties address and family.

On error, err is an Error object, where err.code is the error code. Keep in mind that err.code will be set to 'ENOTFOUND' not only when the host name does not exist but also when the lookup fails in other ways such as no available file descriptors. dns.lookup() does not necessarily have anything to do with the DNS protocol. The implementation uses an operating system facility that can associate names with addresses and vice versa. This implementation can have subtle but important consequences on the behavior of any Node.js program. Please take some time to consult the Implementation considerations section before using dns.lookup().

ArgumentTypeDefaultOptionalDescription
hostnamestringfalseThe host name to resolve.
optionsobject | intenumbergertrueAn options object or record family.
options.familynumber | string0trueThe record family. Must be 4, 6, or 0. For backward compatibility reasons,'IPv4' and 'IPv6' are interpreted as 4 and 6 respectively. The value 0 indicates that IPv4 and IPv6 addresses are both returned. Default: 0.
cbfunctionfalseThe function to call after the method is complete.

dns.promises

This module enables name resolution. For example, use it to look up IP addresses of host names. Although named for the Domain Name System (DNS), it does not always use the DNS protocol for lookups. dns.lookup() uses the operating system facilities to perform name resolution. It may not need to perform any network communication. To perform name resolution the way other applications on the same system do, use dns.lookup().

Example usage:

import { lookup } from 'socket:dns/promises'

lookup(hostname, opts)

External docs: https://nodejs.org/api/dns.html#dnspromiseslookuphostname-options

ArgumentTypeDefaultOptionalDescription
hostnamestringfalseThe host name to resolve.
optsObjecttrueAn options object.
opts.familynumber | string0trueThe record family. Must be 4, 6, or 0. For backward compatibility reasons,'IPv4' and 'IPv6' are interpreted as 4 and 6 respectively. The value 0 indicates that IPv4 and IPv6 addresses are both returned. Default: 0.
Return ValueTypeDescription
Not specifiedPromise

fs

This module enables interacting with the file system in a way modeled on standard POSIX functions.

The Application Sandbox restricts access to the file system.

iOS Application Sandboxing has a set of rules that limits access to the file system. Apps can only access files in their own sandboxed home directory.

DirectoryDescription
DocumentsThe app’s sandboxed documents directory. The contents of this directory are backed up by iTunes and may be set as accessible to the user via iTunes when UIFileSharingEnabled is set to true in the application's info.plist.
LibraryThe app’s sandboxed library directory. The contents of this directory are synchronized via iTunes (except the Library/Caches subdirectory, see below), but never exposed to the user.
Library/CachesThe app’s sandboxed caches directory. The contents of this directory are not synchronized via iTunes and may be deleted by the system at any time. It's a good place to store data which provides a good offline-first experience for the user.
Library/PreferencesThe app’s sandboxed preferences directory. The contents of this directory are synchronized via iTunes. Its purpose is to be used by the Settings app. Avoid creating your own files in this directory.
tmpThe app’s sandboxed temporary directory. The contents of this directory are not synchronized via iTunes and may be deleted by the system at any time. Although, it's recommended that you delete data that is not necessary anymore manually to minimize the space your app takes up on the file system. Use this directory to store data that is only useful during the app runtime.

Example usage:

import * as fs from 'socket:fs';

access(path, mode, callback)

External docs: https://nodejs.org/api/fs.html#fsopenpath-flags-mode-callback Asynchronously check access a file for a given mode calling callback upon success or error.

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
modestring? | function(Error?)?F_OK(0)true
callbackfunction(Error?)?true

accessSync(path, mode)

External docs: https://nodejs.org/api/fs.html#fsopenpath-flags-mode-callback Synchronously check access a file for a given mode calling callback upon success or error.

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
modestring?F_OK(0)true

exists(path, callback)

Checks if a path exists

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
callbackfunction(Boolean)?true

existsSync(path, callback)

Checks if a path exists

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
callbackfunction(Boolean)?true

chmod(path, mode, callback)

External docs: https://nodejs.org/api/fs.html#fschmodpath-mode-callback Asynchronously changes the permissions of a file. No arguments other than a possible exception are given to the completion callback

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
modenumberfalse
callbackfunction(Error?)false

chmodSync(path, mode)

External docs: https://nodejs.org/api/fs.html#fschmodpath-mode-callback Synchronously changes the permissions of a file.

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
modenumberfalse

chown(path, uid, gid, callback)

Changes ownership of file or directory at path with uid and gid.

ArgumentTypeDefaultOptionalDescription
pathstringfalse
uidnumberfalse
gidnumberfalse
callbackfunctionfalse

chownSync(path, uid, gid)

Changes ownership of file or directory at path with uid and gid.

ArgumentTypeDefaultOptionalDescription
pathstringfalse
uidnumberfalse
gidnumberfalse

close(fd, callback)

External docs: https://nodejs.org/api/fs.html#fsclosefd-callback Asynchronously close a file descriptor calling callback upon success or error.

ArgumentTypeDefaultOptionalDescription
fdnumberfalse
callbackfunction(Error?)?true

closeSync(fd)

Synchronously close a file descriptor.

ArgumentTypeDefaultOptionalDescription
fdnumberfalsefd

copyFile(src, dest, flags, callback)

External docs: https://nodejs.org/api/fs.html#fscopyfilesrc-dest-mode-callback Asynchronously copies src to dest calling callback upon success or error.

ArgumentTypeDefaultOptionalDescription
srcstringfalseThe source file path.
deststringfalseThe destination file path.
flagsnumberfalseModifiers for copy operation.
callbackfunction(Error=)trueThe function to call after completion.

copyFileSync(src, dest, flags)

External docs: https://nodejs.org/api/fs.html#fscopyfilesrc-dest-mode-callback Synchronously copies src to dest calling callback upon success or error.

ArgumentTypeDefaultOptionalDescription
srcstringfalseThe source file path.
deststringfalseThe destination file path.
flagsnumberfalseModifiers for copy operation.

createReadStream(path, options)

External docs: https://nodejs.org/api/fs.html#fscreatewritestreampath-options

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
optionsobject?true
Return ValueTypeDescription
Not specifiedReadStream

createWriteStream(path, options)

External docs: https://nodejs.org/api/fs.html#fscreatewritestreampath-options

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
optionsobject?true
Return ValueTypeDescription
Not specifiedWriteStream

fstat(fd, options, callback)

External docs: https://nodejs.org/api/fs.html#fsfstatfd-options-callback Invokes the callback with the <fs.Stats> for the file descriptor. See the POSIX fstat(2) documentation for more detail.

ArgumentTypeDefaultOptionalDescription
fdnumberfalseA file descriptor.
optionsobject? | function?trueAn options object.
callbackfunction?falseThe function to call after completion.

fsync(fd, callback)

Request that all data for the open file descriptor is flushed to the storage device.

ArgumentTypeDefaultOptionalDescription
fdnumberfalseA file descriptor.
callbackfunctionfalseThe function to call after completion.

ftruncate(fd, offset, callback)

Truncates the file up to offset bytes.

ArgumentTypeDefaultOptionalDescription
fdnumberfalseA file descriptor.
offsetnumber= | function0true
callbackfunction?falseThe function to call after completion.

lchown(path, uid, gid, callback)

Chages ownership of link at path with uid and `gid.

ArgumentTypeDefaultOptionalDescription
pathstringfalse
uidnumberfalse
gidnumberfalse
callbackfunctionfalse

link(src, dest, )

Creates a link to dest from src.

ArgumentTypeDefaultOptionalDescription
srcstringfalse
deststringfalse
(Position 0)functionfalse

open(path, flags, mode, options, callback)

External docs: https://nodejs.org/api/fs.html#fsopenpath-flags-mode-callback Asynchronously open a file calling callback upon success or error.

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
flagsstring?rtrue
modestring?0o666true
optionsobject? | function?true
callbackfunction(Error?, number?)?true

openSync(path, flags, mode, options)

Synchronously open a file.

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
flagsstring?rtrue
modestring?0o666true
optionsobject? | function?true

opendir(path, options, callback)

External docs: https://nodejs.org/api/fs.html#fsreaddirpath-options-callback Asynchronously open a directory calling callback upon success or error.

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
optionsobject? | function(Error?, Dir?)true
options.encodingstring?utf8true
options.withFileTypesboolean?falsetrue
callbackfunction(Error?, Dir?)?false

opendirSync(path, options)

External docs: https://nodejs.org/api/fs.html#fsreaddirpath-options-callback Synchronously open a directory.

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
optionsobject? | function(Error?, Dir?)true
options.encodingstring?utf8true
options.withFileTypesboolean?falsetrue
Return ValueTypeDescription
Not specifiedDir

read(fd, buffer, offset, length, position, callback)

External docs: https://nodejs.org/api/fs.html#fsreadfd-buffer-offset-length-position-callback Asynchronously read from an open file descriptor.

ArgumentTypeDefaultOptionalDescription
fdnumberfalse
bufferobject | Buffer | TypedArrayfalseThe buffer that the data will be written to.
offsetnumberfalseThe position in buffer to write the data to.
lengthnumberfalseThe number of bytes to read.
positionnumber | BigInt | nullfalseSpecifies where to begin reading from in the file. If position is null or -1 , data will be read from the current file position, and the file position will be updated. If position is an integer, the file position will be unchanged.
callbackfunction(Error?, number?, Buffer?)false

write(fd, buffer, offset, length, position, callback)

External docs: https://nodejs.org/api/fs.html#fswritefd-buffer-offset-length-position-callback Asynchronously write to an open file descriptor.

ArgumentTypeDefaultOptionalDescription
fdnumberfalse
bufferobject | Buffer | TypedArrayfalseThe buffer that the data will be written to.
offsetnumberfalseThe position in buffer to write the data to.
lengthnumberfalseThe number of bytes to read.
positionnumber | BigInt | nullfalseSpecifies where to begin reading from in the file. If position is null or -1 , data will be read from the current file position, and the file position will be updated. If position is an integer, the file position will be unchanged.
callbackfunction(Error?, number?, Buffer?)false

readdir(path, options, callback)

External docs: https://nodejs.org/api/fs.html#fsreaddirpath-options-callback Asynchronously read all entries in a directory.

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
optionsobject? | function(Error?, object)true
options.encoding ? utf8string?true
options.withFileTypes ? falseboolean?true
callbackfunction(Error?, object)false

readdirSync(path, options)

External docs: https://nodejs.org/api/fs.html#fsreaddirpath-options-callback Synchronously read all entries in a directory.

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
optionsobject? | function(Error?, object)true
options.encoding ? utf8string?true
options.withFileTypes ? falseboolean?true

readFile(path, options, callback)

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URL | numberfalse
optionsobject? | function(Error?, Buffer?)true
options.encoding ? utf8string?true
options.flag ? rstring?true
options.signalAbortSignal?true
callbackfunction(Error?, Buffer?)false

readFileSync(path, } options, options)

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URL | numberfalse
} options{ encoding?: string = 'utf8', flags?: string = 'r'false
optionsobject? | function(Error?, Buffer?)true
options.signalAbortSignal?true

readlink(path, callback)

Reads link at path

ArgumentTypeDefaultOptionalDescription
pathstringfalse
callbackfunction(err, string)false

realpath(path, callback)

Computes real path for path

ArgumentTypeDefaultOptionalDescription
pathstringfalse
callbackfunction(err, string)false

realpathSync(path)

Computes real path for path

ArgumentTypeDefaultOptionalDescription
pathstringfalse

rename(src, dest, callback)

Renames file or directory at src to dest.

ArgumentTypeDefaultOptionalDescription
srcstringfalse
deststringfalse
callbackfunctionfalse

renameSync(src, dest)

Renames file or directory at src to dest, synchronously.

ArgumentTypeDefaultOptionalDescription
srcstringfalse
deststringfalse

rmdir(path, callback)

Removes directory at path.

ArgumentTypeDefaultOptionalDescription
pathstringfalse
callbackfunctionfalse

rmdirSync(path)

Removes directory at path, synchronously.

ArgumentTypeDefaultOptionalDescription
pathstringfalse

statSync(path, options)

Synchronously get the stats of a file

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URL | numberfalsefilename or file descriptor
optionsobject?false
options.encoding ? utf8string?true
options.flag ? rstring?true

stat(path, options, callback)

Get the stats of a file

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URL | numberfalsefilename or file descriptor
optionsobject?false
options.encoding ? utf8string?true
options.flag ? rstring?true
options.signalAbortSignal?true
callbackfunction(Error?, Stats?)false

lstat(path, options, callback)

Get the stats of a symbolic link

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URL | numberfalsefilename or file descriptor
optionsobject?false
options.encoding ? utf8string?true
options.flag ? rstring?true
options.signalAbortSignal?true
callbackfunction(Error?, Stats?)false

symlink(src, dest)

Creates a symlink of src at dest.

ArgumentTypeDefaultOptionalDescription
srcstringfalse
deststringfalse

unlink(path, callback)

Unlinks (removes) file at path.

ArgumentTypeDefaultOptionalDescription
pathstringfalse
callbackfunctionfalse

unlinkSync(path)

Unlinks (removes) file at path, synchronously.

ArgumentTypeDefaultOptionalDescription
pathstringfalse

writeFile(path, data, options, callback)

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URL | numberfalsefilename or file descriptor
datastring | Buffer | TypedArray | DataView | objectfalse
optionsobject?false
options.encoding ? utf8string?true
options.mode ? 0o666string?true
options.flag ? wstring?true
options.signalAbortSignal?true
callbackfunction(Error?)false

writeFileSync(path, data, options)

External docs: https://nodejs.org/api/fs.html#fswritefilesyncfile-data-options Writes data to a file synchronously.

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URL | numberfalsefilename or file descriptor
datastring | Buffer | TypedArray | DataView | objectfalse
optionsobject?false
options.encoding ? utf8string?true
options.mode ? 0o666string?true
options.flag ? wstring?true
options.signalAbortSignal?true

watch(, options, callback)

Watch for changes at path calling callback

ArgumentTypeDefaultOptionalDescription
(Position 0)stringfalse
optionsfunction | objecttrue
options.encodingstringutf8true
callback?functiontrue
Return ValueTypeDescription
Not specifiedWatcher

fs.promises

  • This module enables interacting with the file system in a way modeled on standard POSIX functions.

    The Application Sandbox restricts access to the file system.

    iOS Application Sandboxing has a set of rules that limits access to the file system. Apps can only access files in their own sandboxed home directory.

    DirectoryDescription
    DocumentsThe app’s sandboxed documents directory. The contents of this directory are backed up by iTunes and may be set as accessible to the user via iTunes when UIFileSharingEnabled is set to true in the application's info.plist.
    LibraryThe app’s sandboxed library directory. The contents of this directory are synchronized via iTunes (except the Library/Caches subdirectory, see below), but never exposed to the user.
    Library/CachesThe app’s sandboxed caches directory. The contents of this directory are not synchronized via iTunes and may be deleted by the system at any time. It's a good place to store data which provides a good offline-first experience for the user.
    Library/PreferencesThe app’s sandboxed preferences directory. The contents of this directory are synchronized via iTunes. Its purpose is to be used by the Settings app. Avoid creating your own files in this directory.
    tmpThe app’s sandboxed temporary directory. The contents of this directory are not synchronized via iTunes and may be deleted by the system at any time. Although, it's recommended that you delete data that is not necessary anymore manually to minimize the space your app takes up on the file system. Use this directory to store data that is only useful during the app runtime.

    Example usage:

    import fs from 'socket:fs/promises'

access(path, mode, options)

External docs: https://nodejs.org/dist/latest-v20.x/docs/api/fs.html#fspromisesaccesspath-mode Asynchronously check access a file.

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
modestring?true
optionsobject?true

chmod(path, mode)

External docs: https://nodejs.org/api/fs.html#fspromiseschmodpath-mode

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
modenumberfalse
Return ValueTypeDescription
Not specifiedPromise

chown(path, uid, gid)

Changes ownership of file or directory at path with uid and gid.

ArgumentTypeDefaultOptionalDescription
pathstringfalse
uidnumberfalse
gidnumberfalse
Return ValueTypeDescription
Not specifiedPromise

copyFile(src, dest, flags)

Asynchronously copies src to dest calling callback upon success or error.

ArgumentTypeDefaultOptionalDescription
srcstringfalseThe source file path.
deststringfalseThe destination file path.
flagsnumberfalseModifiers for copy operation.
Return ValueTypeDescription
Not specifiedPromise

lchown(path, uid, gid)

Chages ownership of link at path with uid and `gid.

ArgumentTypeDefaultOptionalDescription
pathstringfalse
uidnumberfalse
gidnumberfalse
Return ValueTypeDescription
Not specifiedPromise

link(src, dest)

Creates a link to dest from dest.

ArgumentTypeDefaultOptionalDescription
srcstringfalse
deststringfalse
Return ValueTypeDescription
Not specifiedPromise

mkdir(path, options)

Asynchronously creates a directory.

ArgumentTypeDefaultOptionalDescription
pathstringfalseThe path to create
optionsobjecttrueThe optional options argument can be an integer specifying mode (permission and sticky bits), or an object with a mode property and a recursive property indicating whether parent directories should be created. Calling fs.mkdir() when path is a directory that exists results in an error only when recursive is false.
options.recursivebooleanfalsetrueRecursively create missing path segments.
options.modenumber0o777trueSet the mode of directory, or missing path segments when recursive is true.
Return ValueTypeDescription
Not specifiedPromiseUpon success, fulfills with undefined if recursive is false, or the first directory path created if recursive is true.

open(path, flags, mode)

External docs: https://nodejs.org/api/fs.html#fspromisesopenpath-flags-mode Asynchronously open a file.

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
flagsstringtruedefault: 'r'
modenumbertruedefault: 0o666
Return ValueTypeDescription
Not specifiedPromise

opendir(path, options)

External docs: https://nodejs.org/api/fs.html#fspromisesopendirpath-options

ArgumentTypeDefaultOptionalDescription
pathstring | Buffer | URLfalse
optionsobject?true
options.encodingstring?utf8true
options.bufferSizenumber?32true

|

0.6.0-rc.8

9 months ago

0.5.4

2 years ago

0.5.3

2 years ago

0.5.2

2 years ago

0.5.0

2 years ago

0.5.1

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.3

2 years ago

0.0.37

2 years ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.32

2 years ago

0.0.33

2 years ago

0.0.34

2 years ago

0.0.35

2 years ago

0.0.36

2 years ago

0.2.13

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.0.28

2 years ago

0.0.29

2 years ago

0.2.1

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.0.3

2 years ago

0.0.26

2 years ago

0.0.9

2 years ago

0.0.27

2 years ago

0.0.8

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago