Parse JavaScript Classes

Cloud Modules

Class Buffer

Container for byte manipulation, Base64 encoding, and string encoding. This is a subset of the Node.js Buffer API.

To use this Cloud Module in Cloud Code, you must require 'buffer' in your JavaScript file.
    var Buffer = require('buffer').Buffer;
You can then start using Buffer in your Cloud Code functions.

Example of using buffer for Base64 decoding and UTF-8:
    var buf = new Buffer('aGVsbG8=', 'base64');
    console.log(buf); // prints [104,101,108,108,111]
    console.log(buf.toString('utf8')); // prints hello

Class Summary
Constructor Attributes Constructor Name and Description
 
Buffer(arg1, encoding)
Constructs a new buffer object.
Field Summary
Field Attributes Field Name and Description
 
Allocated size of the buffer in bytes.
Method Summary
Method Attributes Method Name and Description
<static>  
Buffer.byteLength(string, encoding)
Returns the number of bytes corresponding to the input string with the specified encoding.
<static>  
Buffer.concat(list, length)
Concatenates multiple buffer objects into a new buffer.
 
copy(target, target_start, start, end)
Copies a portion of the original buffer into another target buffer.
 
fill(value, start, end)
Fill all elements from buffer[start] to buffer[end - 1], inclusive, with the specified value.
 
get(i)
Retrieves a specific byte in the buffer.
<static>  
Buffer.isBuffer(b)
Determine if the input object is a Buffer.
 
readInt16BE(offset)
Read a 16-bit big-endian signed integer from the buffer.
 
readInt16LE(offset)
Read a 16-bit little-endian signed integer from the buffer.
 
readInt32BE(offset)
Read a 32-bit big-endian signed integer from the buffer.
 
readInt32LE(offset)
Read a 32-bit little-endian signed integer from the buffer.
 
readInt8(offset)
Read an 8-bit signed integer from the buffer.
 
readUInt16BE(offset)
Read a 16-bit big-endian unsigned integer from the buffer.
 
readUInt16LE(offset)
Read a 16-bit little-endian unsigned integer from the buffer.
 
readUInt32BE(offset)
Read a 32-bit little-endian unsigned integer from the buffer.
 
readUInt32LE(offset)
Read a 32-bit little-endian unsigned integer from the buffer.
 
readUInt8(offset)
Read an 8-bit unsigned integer from the buffer.
 
set(i, v)
Sets a specific byte in the buffer.
 
slice(start, end)
Returns a new buffer containing elements from buffer[start] to buffer[end - 1], inclusive.
 
Get the JSON representation of the buffer.
 
toString(encoding, start, end)
Get the string representation of a portion of the buffer using a specified encoding.
 
write(string, offset, length, encoding)
Write an input string into the buffer, with the specified encoding.
 
writeInt16BE(value, offset)
Write an 16-bit big-endian signed integer at the specified position in the buffer.
 
writeInt16LE(value, offset)
Write an 16-bit little-endian signed integer at the specified position in the buffer.
 
writeInt32BE(value, offset)
Write an 32-bit big-endian signed integer at the specified position in the buffer.
 
writeInt32LE(value, offset)
Write an 32-bit little-endian signed integer at the specified position in the buffer.
 
writeInt8(value, offset)
Write an 8-bit signed integer at the specified position in the buffer.
 
writeUInt16BE(value, offset)
Write an 16-bit big-endian unsigned integer at the specified position in the buffer.
 
writeUInt16LE(value, offset)
Write an 16-bit little-endian unsigned integer at the specified position in the buffer.
 
writeUInt32BE(value, offset)
Write an 32-bit big-endian unsigned integer at the specified position in the buffer.
 
writeUInt32LE(value, offset)
Write an 32-bit little-endian unsigned integer at the specified position in the buffer.
 
writeUInt8(value, offset)
Write an 8-bit unsigned integer at the specified position in the buffer.
Class Detail
Buffer(arg1, encoding)
Constructs a new buffer object. There are 3 ways to call the Buffer constructor:
  • Allocate a buffer of specified size.
        var buf = new Buffer(10);
  • Create a buffer by copying from an array of byte values.
        var buf = new Buffer([1,2,3]);
  • Create a buffer from a string and encoding.
        // Initialize buffer with UTF-8 encoded bytes of a string.
        var buf = new Buffer('hello', 'utf8');
    
        // Initialize buffer with bytes corresponding to a Base64 encoded string.
        var buf = new Buffer('aGVsbG8=', 'base64');
Parameters:
{Number|Array|String} arg1
Number: The number of bytes to allocate for the buffer.
Array: The array of bytes to put in the buffer.
String: The input string.
{String} encoding Optional, Default: 'utf8'
The string encoding for converting the input string to bytes before writing these bytes to the buffer. This argument should only be specified when the arg1 is a String.
Field Detail
length
Allocated size of the buffer in bytes.
Method Detail
<static> {Number} Buffer.byteLength(string, encoding)
Returns the number of bytes corresponding to the input string with the specified encoding. This is also number of bytes written if Buffer#write were called on the entire input string.
Parameters:
{String} string
The input string.
{String} encoding Optional, Default: 'utf8'
The string encoding for determining byte length.
Returns:
{Number}

<static> {Buffer} Buffer.concat(list, length)
Concatenates multiple buffer objects into a new buffer.
Parameters:
{Array} list
The array of Buffer objects to concatenate.
{Number} length Optional
The total byte length of all buffers to be concatenated. The caller should provide this if available, otherwise this method will loop through all buffers first to determine the total length.
Returns:
{Buffer} A new buffer that contains copied contents from all buffers in list.

copy(target, target_start, start, end)
Copies a portion of the original buffer into another target buffer. Elements from buffer[start] to buffer[end - 1], inclusive, in the original buffer will be copied into the target buffer. The copied contents will be written into the target buffer starting at target[target_start]. If the target buffer is not big enough, this method will copy as much as possible until the end of the target buffer, and no exception will be thrown.
Parameters:
{Buffer} target
The buffer to copy into.
{Number} target_start Optional, Default: 0
The start index in the target buffer to write the copied elements.
{Number} start Optional, Default: 0
The index in the original buffer that corresponds to the beginning of the copied portion.
{Number} end Optional, Default: buffer.length
The index in the original buffer that corresponds to the element that's just after the end of the copied portion.

fill(value, start, end)
Fill all elements from buffer[start] to buffer[end - 1], inclusive, with the specified value.
Parameters:
{Number} value
The value to set.
{Number} start Optional, Default: 0
The index to start filling from.
{Number} end Optional, Default: buffer.length
The index just after the last element to fill to.

{Number} get(i)
Retrieves a specific byte in the buffer.
Parameters:
{Number} i
The index of the byte to retrieve.
Throws:
{RangeError}
If i is outside the buffer's index range.
Returns:
{Number}

<static> {Boolean} Buffer.isBuffer(b)
Determine if the input object is a Buffer.
Parameters:
{Object} b
input object
Returns:
{Boolean}

{Number} readInt16BE(offset)
Read a 16-bit big-endian signed integer from the buffer.
Parameters:
offset
The byte index in the buffer to read from.
Returns:
{Number}

{Number} readInt16LE(offset)
Read a 16-bit little-endian signed integer from the buffer.
Parameters:
offset
The byte index in the buffer to read from.
Returns:
{Number}

{Number} readInt32BE(offset)
Read a 32-bit big-endian signed integer from the buffer.
Parameters:
offset
The byte index in the buffer to read from.
Returns:
{Number}

{Number} readInt32LE(offset)
Read a 32-bit little-endian signed integer from the buffer.
Parameters:
offset
The byte index in the buffer to read from.
Returns:
{Number}

{Number} readInt8(offset)
Read an 8-bit signed integer from the buffer.
Parameters:
offset
The byte index in the buffer to read from.
Returns:
{Number}

{Number} readUInt16BE(offset)
Read a 16-bit big-endian unsigned integer from the buffer.
Parameters:
offset
The byte index in the buffer to read from.
Returns:
{Number}

{Number} readUInt16LE(offset)
Read a 16-bit little-endian unsigned integer from the buffer.
Parameters:
offset
The byte index in the buffer to read from.
Returns:
{Number}

{Number} readUInt32BE(offset)
Read a 32-bit little-endian unsigned integer from the buffer.
Parameters:
offset
The byte index in the buffer to read from.
Returns:
{Number}

{Number} readUInt32LE(offset)
Read a 32-bit little-endian unsigned integer from the buffer.
Parameters:
offset
The byte index in the buffer to read from.
Returns:
{Number}

{Number} readUInt8(offset)
Read an 8-bit unsigned integer from the buffer.
Parameters:
offset
The byte index in the buffer to read from.
Returns:
{Number}

set(i, v)
Sets a specific byte in the buffer.
Parameters:
{Number} i
The index of the byte to set.
{Number} v
The value to set the byte to.
Throws:
{RangeError}
If i is outside the buffer's index range.

{Buffer} slice(start, end)
Returns a new buffer containing elements from buffer[start] to buffer[end - 1], inclusive. The returned buffer shares the same memory as the original so modifying it will reflect in the original as well.
Parameters:
{Number} start Optional, Default: 0
The index in the original buffer that corresponds to the beginning of the new buffer.
{Number} end Optional, Default: buffer.length
The index in the original buffer that corresponds to the element that's just after the end of the new buffer.
Returns:
{Buffer}

{String} toJSON()
Get the JSON representation of the buffer.
Returns:
{String}

{String} toString(encoding, start, end)
Get the string representation of a portion of the buffer using a specified encoding. If start and end are not passed, the string representation of the entire buffer will be returned. Invalid bytes for an encoding will generally, but not always, yield strings containing the Unicode replacement character (U+FFFD). The following string encodings are supported:
Parameters:
encoding Optional, Default: 'utf8
The encoding used to convert the buffer's bytes to string.
start Optional, Default: 0
The byte index in the buffer to start for string output.
end Optional
The byte index in the buffer that's just past the last byte that's used for string output.
Returns:
{String}

{Number} write(string, offset, length, encoding)
Write an input string into the buffer, with the specified encoding. If the input is longer than the available space in the buffer, extra bytes are ignored. The following string encodings are supported:
Parameters:
{Number} string
The input string to write.
{Number} offset
The byte index in the buffer to start writing at.
{Number} length
The number of bytes to write.
{String} encoding Optional, Default: 'utf8'
The string encoding to use.
Returns:
{Number} The number of bytes written.

writeInt16BE(value, offset)
Write an 16-bit big-endian signed integer at the specified position in the buffer.
Parameters:
value
The signed integer value to write.
offset
The byte index in the buffer start writing at.

writeInt16LE(value, offset)
Write an 16-bit little-endian signed integer at the specified position in the buffer.
Parameters:
value
The signed integer value to write.
offset
The byte index in the buffer start writing at.

writeInt32BE(value, offset)
Write an 32-bit big-endian signed integer at the specified position in the buffer.
Parameters:
value
The signed integer value to write.
offset
The byte index in the buffer start writing at.

writeInt32LE(value, offset)
Write an 32-bit little-endian signed integer at the specified position in the buffer.
Parameters:
value
The signed integer value to write.
offset
The byte index in the buffer start writing at.

writeInt8(value, offset)
Write an 8-bit signed integer at the specified position in the buffer.
Parameters:
value
The signed integer value to write.
offset
The byte index in the buffer start writing at.

writeUInt16BE(value, offset)
Write an 16-bit big-endian unsigned integer at the specified position in the buffer.
Parameters:
value
The unsigned integer value to write.
offset
The byte index in the buffer start writing at.

writeUInt16LE(value, offset)
Write an 16-bit little-endian unsigned integer at the specified position in the buffer.
Parameters:
value
The unsigned integer value to write.
offset
The byte index in the buffer start writing at.

writeUInt32BE(value, offset)
Write an 32-bit big-endian unsigned integer at the specified position in the buffer.
Parameters:
value
The unsigned integer value to write.
offset
The byte index in the buffer start writing at.

writeUInt32LE(value, offset)
Write an 32-bit little-endian unsigned integer at the specified position in the buffer.
Parameters:
value
The unsigned integer value to write.
offset
The byte index in the buffer start writing at.

writeUInt8(value, offset)
Write an 8-bit unsigned integer at the specified position in the buffer.
Parameters:
value
The unsigned integer value to write.
offset
The byte index in the buffer write to.

Documentation generated by JsDoc Toolkit.