Members
(static) POLLERR :number
- Source:
- Default Value:
- 8
Type:
- number
(static) POLLHUP :number
- Source:
- Default Value:
- 16
Type:
- number
(static) POLLIN :number
- Source:
- Default Value:
- 1
Type:
- number
(static) POLLMSG :number
- Source:
- Default Value:
- 1024
Type:
- number
(static) POLLNVAL :number
- Source:
- Default Value:
- 32
Type:
- number
(static) POLLOUT :number
- Source:
- Default Value:
- 4
Type:
- number
(static) POLLPRI :number
- Source:
- Default Value:
- 2
Type:
- number
(static) POLLRDBAND :number
- Source:
- Default Value:
- 128
Type:
- number
(static) POLLRDHUP :number
- Source:
- Default Value:
- 8192
Type:
- number
(static) POLLRDNORM :number
- Source:
- Default Value:
- 64
Type:
- number
(static) POLLREMOVE :number
- Source:
- Default Value:
- 4096
Type:
- number
(static) POLLWRBAND :number
- Source:
- Default Value:
- 512
Type:
- number
(static) POLLWRNORM :number
- Source:
- Default Value:
- 256
Type:
- number
(static) SEEK_CUR :number
- Source:
- Default Value:
- 1
Seek from current position
Type:
- number
(static) SEEK_END :number
- Source:
- Default Value:
- 2
Seek from end of file
Type:
- number
(static) SEEK_SET :number
- Source:
Seek from start of file
Type:
- number
Methods
(static) append(pathname, modeopt) → {number}
- Source:
- See:
Open a file for appending. If the file does not exist it is created. If it exists its contents remain untouched.
Note that the file pointer will always be set to EOF before any write operation.
Note that the file is always open in write only mode.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pathname |
string | Path to file |
||
mode |
number |
<optional> |
0644
|
File mode bits of file in case it needs to be created |
Throws:
Returns:
The file descriptor
- Type
- number
(static) close(fd, fail_if_closedopt) → {0}
- Source:
Close an open file
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fd |
number | The file descriptor |
||
fail_if_closed |
boolean |
<optional> |
true
|
Fail if file is already closed |
Throws:
Returns:
- Type
- 0
(static) create(pathname, modeopt, accessopt) → {number}
- Source:
- See:
Open a file. If the file does not exist it is created. If it exists its contents remain untouched.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pathname |
string | Path to file |
||
mode |
number |
<optional> |
0644
|
File mode bits of file in case it needs to be created |
access |
string |
<optional> |
'rw'
|
Access mode of file ('r', 'w', or 'rw') |
Throws:
Returns:
The file descriptor
- Type
- number
(static) dup(fd) → {number}
- Source:
Duplicate an open file descriptor
Parameters:
Name | Type | Description |
---|---|---|
fd |
number | The existing file descriptor |
Throws:
Returns:
The new file descriptor
- Type
- number
(static) dup2(openFd, changedFd) → {number}
- Source:
Duplicate an open file descriptor assigning it to another custom fd
Parameters:
Name | Type | Description |
---|---|---|
openFd |
number | The existing file descriptor |
changedFd |
number | The file descriptor that will be changed |
Throws:
Returns:
The changed file descriptor
- Type
- number
(static) open(pathname, accessopt) → {number}
- Source:
- See:
Open an existing file.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pathname |
string | Path to file |
||
access |
string |
<optional> |
'rw'
|
Access mode ('r', 'w', or 'rw') |
Throws:
Returns:
The file descriptor
- Type
- number
(static) pipe() → {Array.<number>}
- Source:
Create a pipe
Throws:
Returns:
An array with two file descriptors where [0]
item is the read end of the
pipe and [1]
is the write end.
- Type
- Array.<number>
(static) poll(fds, timeoutopt) → {number}
- Source:
The poll() function provides applications with a mechanism for multiplexing input/output over a set of file descriptors.
For each member of the array pointed to by fds
, poll() shall examine the
given file descriptor for the event(s) specified in events.
The poll() function shall identify those file descriptors on which an application can read or write data, or on which certain events have occurred.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fds |
Pollfd | File descriptors and events to check |
||
timeout |
number |
<optional> |
-1
|
Timeout in milliseconds or -1 to wait forever |
Throws:
Returns:
Count of fds with events or 0 on timeout
- Type
- number
(static) read(fd, buf, countopt) → {number}
- Source:
Read bytes from an open file
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fd |
number | An open file desriptor |
||
buf |
Uint8Array | Buffer to fill with read bytes |
||
count |
number |
<optional> |
-1
|
Maximum number of bytes to read, or Note that it is not the same |
Throws:
Returns:
The number of bytes read (with 0 meaning end of file).
In the case where count = -1
, a return less than buffer length means that
EOF was reached.
- Type
- number
(static) read_fully(fd) → {Uint8Array}
- Source:
Read contents of a fd until it is exhausted and return them as an Uint8Array.
Parameters:
Name | Type | Description |
---|---|---|
fd |
number | An open file desriptor |
Throws:
Returns:
The bytes contained by the file
- Type
- Uint8Array
(static) read_string(fd) → {string}
- Source:
Read contents of a fd until it is exhausted and return them as a string.
The bytes are interpreted as UTF-8.
Parameters:
Name | Type | Description |
---|---|---|
fd |
number | An open file desriptor |
Throws:
Returns:
The contents of the file interpreted as an UTF-8 string
- Type
- string
(static) seek(fd, offset, whence) → {number}
- Source:
Set the pointer of a file descriptor to a given value
Parameters:
Name | Type | Description |
---|---|---|
fd |
number | An open file descriptor |
offset |
number | Relative offset for file pointer |
whence |
number | Base of offset. One of the values: module:io.SEEK_SET, module:io.SEEK_CUR, or module:io.SEEK_END. |
Throws:
Returns:
The resulting offset measured from start of file
- Type
- number
(static) tell(fd) → {number}
- Source:
Retrieve the current offset of the file pointer from the start of the file.
Parameters:
Name | Type | Description |
---|---|---|
fd |
number | An open file desriptor |
Throws:
Returns:
The offset of the file pointer
- Type
- number
(static) truncate(pathname, modeopt, accessopt) → {number}
- Source:
- See:
Open a file and empty it. If the file does not exist it is created.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pathname |
string | Path to file |
||
mode |
number |
<optional> |
0644
|
File mode bits of file in case it needs to be created |
access |
string |
<optional> |
'rw'
|
Access mode of file ('r', 'w', or 'rw') |
Throws:
Returns:
The file descriptor
- Type
- number
(static) write(fd, buf, countopt) → {number}
- Source:
Write bytes to an open file
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fd |
number | An open file desriptor |
||
buf |
Uint8Array | Buffer containing bytes to write |
||
count |
number |
<optional> |
-1
|
Maximum number of bytes to write or -1 to keep writing until all buffer has been written. Note that it is not the same |
Throws:
Returns:
The number of bytes written
- Type
- number
(static) write_string(fd, str) → {number}
- Source:
Write a string as UTF-8 bytes to an open file
Parameters:
Name | Type | Description |
---|---|---|
fd |
number | An open file desriptor |
str |
string | The string to write |
Throws:
Returns:
The number of bytes written
- Type
- number