Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
docs: fix docs to not suggest variable leaks
Browse files Browse the repository at this point in the history
Fixes #2106.
  • Loading branch information
koichik committed Dec 27, 2011
1 parent a337ac7 commit e1c043f
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 146 deletions.
133 changes: 69 additions & 64 deletions doc/api/buffers.markdown
Expand Up @@ -43,18 +43,19 @@ Allocates a new buffer of `size` octets.

Allocates a new buffer using an `array` of octets.

### new Buffer(str, encoding='utf8')
### new Buffer(str, [encoding])

Allocates a new buffer containing the given `str`.
`encoding` defaults to `'utf8'`.

### buffer.write(string, offset=0, length=buffer.length-offset, encoding='utf8')
### buffer.write(string, [offset], [length], [encoding])

Writes `string` to the buffer at `offset` using the given encoding. `length` is
Writes `string` to the buffer at `offset` using the given encoding.
`offset` defaults to `0`, `encoding` defaults to `'utf8'`. `length` is
the number of bytes to write. Returns number of octets written. If `buffer` did
not contain enough space to fit the entire string, it will write a partial
amount of the string. The method will not write partial characters.

Example: write a utf8 string into a buffer, then print it
amount of the string. `length` defaults to `buffer.length - offset`.
The method will not write partial characters.

buf = new Buffer(256);
len = buf.write('\u00bd + \u00bc = \u00be', 0);
Expand All @@ -65,10 +66,11 @@ bytes written) is set in `Buffer._charsWritten` and will be overwritten the
next time `buf.write()` is called.


### buffer.toString(encoding, start=0, end=buffer.length)
### buffer.toString(encoding, [start], [end])

Decodes and returns a string from buffer data encoded with `encoding`
beginning at `start` and ending at `end`.
(defaults to `'utf8'`) beginning at `start` (defaults to `0`) and ending at
`end` (defaults to `buffer.length`).

See `buffer.write()` example, above.

Expand All @@ -95,11 +97,11 @@ Example: copy an ASCII string into a buffer, one byte at a time:

Tests if `obj` is a `Buffer`.

### Buffer.byteLength(string, encoding='utf8')
### Buffer.byteLength(string, [encoding])

Gives the actual byte length of a string. This is not the same as
`String.prototype.length` since that returns the number of *characters* in a
string.
Gives the actual byte length of a string. `encoding` defaults to `'utf8'`.
This is not the same as `String.prototype.length` since that returns the
number of *characters* in a string.

Example:

Expand All @@ -126,9 +128,11 @@ buffer object. It does not change when the contents of the buffer are changed.
// 1234
// 1234

### buffer.copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
### buffer.copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd])

Does copy between buffers. The source and target regions can be overlapped.
`targetStart` and `sourceStart` default to `0`.
`sourceEnd` defaults to `buffer.length`.

Example: build two Buffers, then copy `buf1` from byte 16 through byte 19
into `buf2`, starting at the 8th byte in `buf2`.
Expand All @@ -147,11 +151,11 @@ into `buf2`, starting at the 8th byte in `buf2`.
// !!!!!!!!qrst!!!!!!!!!!!!!


### buffer.slice(start, end=buffer.length)
### buffer.slice([start], [end])

Returns a new buffer which references the
same memory as the old, but offset and cropped by the `start` and `end`
indexes.
Returns a new buffer which references the same memory as the old, but offset
and cropped by the `start` (defaults to `0`) and `end` (defaults to
`buffer.length`) indexes.

**Modifying the new buffer slice will modify memory in the original buffer!**

Expand All @@ -172,12 +176,12 @@ byte from the original Buffer.
// abc
// !bc

### buffer.readUInt8(offset, noAssert=false)
### buffer.readUInt8(offset, [noAssert])

Reads an unsigned 8 bit integer from the buffer at the specified offset.

Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer.
may be beyond the end of the buffer. Defaults to `false`.

Example:

Expand All @@ -197,14 +201,14 @@ Example:
// 0x23
// 0x42

### buffer.readUInt16LE(offset, noAssert=false)
### buffer.readUInt16BE(offset, noAssert=false)
### buffer.readUInt16LE(offset, [noAssert])
### buffer.readUInt16BE(offset, [noAssert])

Reads an unsigned 16 bit integer from the buffer at the specified offset with
specified endian format.

Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer.
may be beyond the end of the buffer. Defaults to `false`.

Example:

Expand All @@ -229,14 +233,14 @@ Example:
// 0x2342
// 0x4223

### buffer.readUInt32LE(offset, noAssert=false)
### buffer.readUInt32BE(offset, noAssert=false)
### buffer.readUInt32LE(offset, [noAssert])
### buffer.readUInt32BE(offset, [noAssert])

Reads an unsigned 32 bit integer from the buffer at the specified offset with
specified endian format.

Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer.
may be beyond the end of the buffer. Defaults to `false`.

Example:

Expand All @@ -253,48 +257,48 @@ Example:
// 0x03042342
// 0x42230403

### buffer.readInt8(offset, noAssert=false)
### buffer.readInt8(offset, [noAssert])

Reads a signed 8 bit integer from the buffer at the specified offset.

Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer.
may be beyond the end of the buffer. Defaults to `false`.

Works as `buffer.readUInt8`, except buffer contents are treated as two's
complement signed values.

### buffer.readInt16LE(offset, noAssert=false)
### buffer.readInt16BE(offset, noAssert=false)
### buffer.readInt16LE(offset, [noAssert])
### buffer.readInt16BE(offset, [noAssert])

Reads a signed 16 bit integer from the buffer at the specified offset with
specified endian format.

Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer.
may be beyond the end of the buffer. Defaults to `false`.

Works as `buffer.readUInt16*`, except buffer contents are treated as two's
complement signed values.

### buffer.readInt32LE(offset, noAssert=false)
### buffer.readInt32BE(offset, noAssert=false)
### buffer.readInt32LE(offset, [noAssert])
### buffer.readInt32BE(offset, [noAssert])

Reads a signed 32 bit integer from the buffer at the specified offset with
specified endian format.

Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer.
may be beyond the end of the buffer. Defaults to `false`.

Works as `buffer.readUInt32*`, except buffer contents are treated as two's
complement signed values.

### buffer.readFloatLE(offset, noAssert=false)
### buffer.readFloatBE(offset, noAssert=false)
### buffer.readFloatLE(offset, [noAssert])
### buffer.readFloatBE(offset, [noAssert])

Reads a 32 bit float from the buffer at the specified offset with specified
endian format.

Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer.
may be beyond the end of the buffer. Defaults to `false`.

Example:

Expand All @@ -309,14 +313,14 @@ Example:

// 0x01

### buffer.readDoubleLE(offset, noAssert=false)
### buffer.readDoubleBE(offset, noAssert=false)
### buffer.readDoubleLE(offset, [noAssert])
### buffer.readDoubleBE(offset, [noAssert])

Reads a 64 bit double from the buffer at the specified offset with specified
endian format.

Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer.
may be beyond the end of the buffer. Defaults to `false`.

Example:

Expand All @@ -335,15 +339,15 @@ Example:

// 0.3333333333333333

### buffer.writeUInt8(value, offset, noAssert=false)
### buffer.writeUInt8(value, offset, [noAssert])

Writes `value` to the buffer at the specified offset. Note, `value` must be a
valid unsigned 8 bit integer.

Set `noAssert` to true to skip validation of `value` and `offset`. This means
that `value` may be too large for the specific function and `offset` may be
beyond the end of the buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.
should not be used unless you are certain of correctness. Defaults to `false`.

Example:

Expand All @@ -357,16 +361,16 @@ Example:

// <Buffer 03 04 23 42>

### buffer.writeUInt16LE(value, offset, noAssert=false)
### buffer.writeUInt16BE(value, offset, noAssert=false)
### buffer.writeUInt16LE(value, offset, [noAssert])
### buffer.writeUInt16BE(value, offset, [noAssert])

Writes `value` to the buffer at the specified offset with specified endian
format. Note, `value` must be a valid unsigned 16 bit integer.

Set `noAssert` to true to skip validation of `value` and `offset`. This means
that `value` may be too large for the specific function and `offset` may be
beyond the end of the buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.
should not be used unless you are certain of correctness. Defaults to `false`.

Example:

Expand All @@ -384,16 +388,16 @@ Example:
// <Buffer de ad be ef>
// <Buffer ad de ef be>

### buffer.writeUInt32LE(value, offset, noAssert=false)
### buffer.writeUInt32BE(value, offset, noAssert=false)
### buffer.writeUInt32LE(value, offset, [noAssert])
### buffer.writeUInt32BE(value, offset, [noAssert])

Writes `value` to the buffer at the specified offset with specified endian
format. Note, `value` must be a valid unsigned 32 bit integer.

Set `noAssert` to true to skip validation of `value` and `offset`. This means
that `value` may be too large for the specific function and `offset` may be
beyond the end of the buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.
should not be used unless you are certain of correctness. Defaults to `false`.

Example:

Expand All @@ -409,57 +413,57 @@ Example:
// <Buffer fe ed fa ce>
// <Buffer ce fa ed fe>

### buffer.writeInt8(value, offset, noAssert=false)
### buffer.writeInt8(value, offset, [noAssert])

Writes `value` to the buffer at the specified offset. Note, `value` must be a
valid signed 8 bit integer.

Set `noAssert` to true to skip validation of `value` and `offset`. This means
that `value` may be too large for the specific function and `offset` may be
beyond the end of the buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.
should not be used unless you are certain of correctness. Defaults to `false`.

Works as `buffer.writeUInt8`, except value is written out as a two's complement
signed integer into `buffer`.

### buffer.writeInt16LE(value, offset, noAssert=false)
### buffer.writeInt16BE(value, offset, noAssert=false)
### buffer.writeInt16LE(value, offset, [noAssert])
### buffer.writeInt16BE(value, offset, [noAssert])

Writes `value` to the buffer at the specified offset with specified endian
format. Note, `value` must be a valid signed 16 bit integer.

Set `noAssert` to true to skip validation of `value` and `offset`. This means
that `value` may be too large for the specific function and `offset` may be
beyond the end of the buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.
should not be used unless you are certain of correctness. Defaults to `false`.

Works as `buffer.writeUInt16*`, except value is written out as a two's
complement signed integer into `buffer`.

### buffer.writeInt32LE(value, offset, noAssert=false)
### buffer.writeInt32BE(value, offset, noAssert=false)
### buffer.writeInt32LE(value, offset, [noAssert])
### buffer.writeInt32BE(value, offset, [noAssert])

Writes `value` to the buffer at the specified offset with specified endian
format. Note, `value` must be a valid signed 32 bit integer.

Set `noAssert` to true to skip validation of `value` and `offset`. This means
that `value` may be too large for the specific function and `offset` may be
beyond the end of the buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.
should not be used unless you are certain of correctness. Defaults to `false`.

Works as `buffer.writeUInt32*`, except value is written out as a two's
complement signed integer into `buffer`.

### buffer.writeFloatLE(value, offset, noAssert=false)
### buffer.writeFloatBE(value, offset, noAssert=false)
### buffer.writeFloatLE(value, offset, [noAssert])
### buffer.writeFloatBE(value, offset, [noAssert])

Writes `value` to the buffer at the specified offset with specified endian
format. Note, `value` must be a valid 32 bit float.

Set `noAssert` to true to skip validation of `value` and `offset`. This means
that `value` may be too large for the specific function and `offset` may be
beyond the end of the buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.
should not be used unless you are certain of correctness. Defaults to `false`.

Example:

Expand All @@ -475,16 +479,16 @@ Example:
// <Buffer 4f 4a fe bb>
// <Buffer bb fe 4a 4f>

### buffer.writeDoubleLE(value, offset, noAssert=false)
### buffer.writeDoubleBE(value, offset, noAssert=false)
### buffer.writeDoubleLE(value, offset, [noAssert])
### buffer.writeDoubleBE(value, offset, [noAssert])

Writes `value` to the buffer at the specified offset with specified endian
format. Note, `value` must be a valid 64 bit double.

Set `noAssert` to true to skip validation of `value` and `offset`. This means
that `value` may be too large for the specific function and `offset` may be
beyond the end of the buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.
should not be used unless you are certain of correctness. Defaults to `false`.

Example:

Expand All @@ -500,10 +504,11 @@ Example:
// <Buffer 43 eb d5 b7 dd f9 5f d7>
// <Buffer d7 5f f9 dd b7 d5 eb 43>

### buffer.fill(value, offset=0, end=buffer.length)
### buffer.fill(value, [offset], [end])

Fills the buffer with the specified value. If the offset and end are not
given it will fill the entire buffer.
Fills the buffer with the specified value. If the `offset` (defaults to `0`)
and `end` (defaults to `buffer.length`) are not given it will fill the entire
buffer.

var b = new Buffer(50);
b.fill("h");
Expand Down
4 changes: 2 additions & 2 deletions doc/api/child_processes.markdown
Expand Up @@ -50,7 +50,7 @@ Example:
grep.stdin.end();


### child_process.spawn(command, args=[], [options])
### child_process.spawn(command, [args], [options])

Launches a new process with the given `command`, with command line arguments in `args`.
If omitted, `args` defaults to an empty Array.
Expand Down Expand Up @@ -259,7 +259,7 @@ processes:



### child.kill(signal='SIGTERM')
### child.kill([signal])

Send a signal to the child process. If no argument is given, the process will
be sent `'SIGTERM'`. See `signal(7)` for a list of available signals.
Expand Down

0 comments on commit e1c043f

Please sign in to comment.