safe-buffer
- Version 5.2.1
- Published
- 32.1 kB
- No dependencies
- MIT license
Install
npm i safe-buffer
yarn add safe-buffer
pnpm add safe-buffer
Overview
Safer Node.js Buffer API
Index
Namespaces
Namespaces
namespace safe-buffer
module 'safe-buffer' {}
class Buffer
class Buffer {}
constructor
constructor(str: string, encoding?: string);
Allocates a new buffer containing the given {str}.
Parameter str
String to store in buffer.
Parameter encoding
encoding to use, optional. Default is 'utf8'
constructor
constructor(size: number);
Allocates a new buffer of {size} octets.
Parameter size
count of octets to allocate.
constructor
constructor(array: Uint8Array);
Allocates a new buffer containing the given {array} of octets.
Parameter array
The octets to store.
constructor
constructor(arrayBuffer: ArrayBuffer);
Produces a Buffer backed by the same allocated memory as the given {ArrayBuffer}.
Parameter arrayBuffer
The ArrayBuffer with which to share memory.
constructor
constructor(array: any[]);
Allocates a new buffer containing the given {array} of octets.
Parameter array
The octets to store.
constructor
constructor(buffer: Buffer);
Copies the passed {buffer} data onto a new {Buffer} instance.
Parameter buffer
The buffer to copy.
property length
length: number;
property prototype
prototype: Buffer;
method alloc
static alloc: ( size: number, fill?: string | Buffer | number, encoding?: string) => Buffer;
Allocates a new buffer of {size} octets.
Parameter size
count of octets to allocate.
Parameter fill
if specified, buffer will be initialized by calling buf.fill(fill). If parameter is omitted, buffer will be filled with zeros.
Parameter encoding
encoding used for call to buf.fill while initalizing
method allocUnsafe
static allocUnsafe: (size: number) => Buffer;
Allocates a new buffer of {size} octets, leaving memory not initialized, so the contents of the newly created Buffer are unknown and may contain sensitive data.
Parameter size
count of octets to allocate
method allocUnsafeSlow
static allocUnsafeSlow: (size: number) => Buffer;
Allocates a new non-pooled buffer of {size} octets, leaving memory not initialized, so the contents of the newly created Buffer are unknown and may contain sensitive data.
Parameter size
count of octets to allocate
method byteLength
static byteLength: (string: string, encoding?: string) => number;
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.
Parameter string
string to test.
Parameter encoding
encoding used to evaluate (defaults to 'utf8')
method compare
static compare: (buf1: Buffer, buf2: Buffer) => number;
The same as buf1.compare(buf2).
method concat
static concat: (list: Buffer[], totalLength?: number) => Buffer;
Returns a buffer which is the result of concatenating all the buffers in the list together.
If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer. If the list has exactly one item, then the first item of the list is returned. If the list has more than one item, then a new Buffer is created.
Parameter list
An array of Buffer objects to concatenate
Parameter totalLength
Total length of the buffers when concatenated. If totalLength is not provided, it is read from the buffers in the list. However, this adds an additional loop to the function, so it is faster to provide the length explicitly.
method copy
copy: ( targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number) => number;
method equals
equals: (otherBuffer: Buffer) => boolean;
method fill
fill: (value: any, offset?: number, end?: number) => this;
method from
static from: { (array: any[]): Buffer; (arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer; (buffer: Buffer): Buffer; (str: string, encoding?: string): Buffer;};
Allocates a new Buffer using an {array} of octets.
Parameter array
When passed a reference to the .buffer property of a TypedArray instance, the newly created Buffer will share the same allocated memory as the TypedArray. The optional {byteOffset} and {length} arguments specify a memory range within the {arrayBuffer} that will be shared by the Buffer.
Parameter arrayBuffer
The .buffer property of a TypedArray or a new ArrayBuffer()
Parameter byteOffset
Parameter length
Copies the passed {buffer} data onto a new Buffer instance.
Parameter buffer
Creates a new Buffer containing the given JavaScript string {str}. If provided, the {encoding} parameter identifies the character encoding. If not provided, {encoding} defaults to 'utf8'.
Parameter str
method includes
includes: ( value: string | number | Buffer, byteOffset?: number, encoding?: string) => boolean;
method indexOf
indexOf: ( value: string | number | Buffer, byteOffset?: number, encoding?: string) => number;
method isBuffer
static isBuffer: (obj: any) => obj is Buffer;
Returns true if {obj} is a Buffer
Parameter obj
object to test.
method isEncoding
static isEncoding: (encoding: string) => boolean;
Returns true if {encoding} is a valid encoding argument. Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex'
Parameter encoding
string to test.
method lastIndexOf
lastIndexOf: ( value: string | number | Buffer, byteOffset?: number, encoding?: string) => number;
method readDoubleBE
readDoubleBE: (offset: number, noAssert?: boolean) => number;
method readDoubleLE
readDoubleLE: (offset: number, noAssert?: boolean) => number;
method readFloatBE
readFloatBE: (offset: number, noAssert?: boolean) => number;
method readFloatLE
readFloatLE: (offset: number, noAssert?: boolean) => number;
method readInt16BE
readInt16BE: (offset: number, noAssert?: boolean) => number;
method readInt16LE
readInt16LE: (offset: number, noAssert?: boolean) => number;
method readInt32BE
readInt32BE: (offset: number, noAssert?: boolean) => number;
method readInt32LE
readInt32LE: (offset: number, noAssert?: boolean) => number;
method readInt8
readInt8: (offset: number, noAssert?: boolean) => number;
method readIntBE
readIntBE: (offset: number, byteLength: number, noAssert?: boolean) => number;
method readIntLE
readIntLE: (offset: number, byteLength: number, noAssert?: boolean) => number;
method readUInt16BE
readUInt16BE: (offset: number, noAssert?: boolean) => number;
method readUInt16LE
readUInt16LE: (offset: number, noAssert?: boolean) => number;
method readUInt32BE
readUInt32BE: (offset: number, noAssert?: boolean) => number;
method readUInt32LE
readUInt32LE: (offset: number, noAssert?: boolean) => number;
method readUInt8
readUInt8: (offset: number, noAssert?: boolean) => number;
method readUIntBE
readUIntBE: (offset: number, byteLength: number, noAssert?: boolean) => number;
method readUIntLE
readUIntLE: (offset: number, byteLength: number, noAssert?: boolean) => number;
method slice
slice: (start?: number, end?: number) => Buffer;
method swap16
swap16: () => Buffer;
method swap32
swap32: () => Buffer;
method swap64
swap64: () => Buffer;
method toJSON
toJSON: () => { type: 'Buffer'; data: any[] };
method toString
toString: (encoding?: string, start?: number, end?: number) => string;
method write
write: ( string: string, offset?: number, length?: number, encoding?: string) => number;
method writeDoubleBE
writeDoubleBE: (value: number, offset: number, noAssert?: boolean) => number;
method writeDoubleLE
writeDoubleLE: (value: number, offset: number, noAssert?: boolean) => number;
method writeFloatBE
writeFloatBE: (value: number, offset: number, noAssert?: boolean) => number;
method writeFloatLE
writeFloatLE: (value: number, offset: number, noAssert?: boolean) => number;
method writeInt16BE
writeInt16BE: (value: number, offset: number, noAssert?: boolean) => number;
method writeInt16LE
writeInt16LE: (value: number, offset: number, noAssert?: boolean) => number;
method writeInt32BE
writeInt32BE: (value: number, offset: number, noAssert?: boolean) => number;
method writeInt32LE
writeInt32LE: (value: number, offset: number, noAssert?: boolean) => number;
method writeInt8
writeInt8: (value: number, offset: number, noAssert?: boolean) => number;
method writeIntBE
writeIntBE: ( value: number, offset: number, byteLength: number, noAssert?: boolean) => number;
method writeIntLE
writeIntLE: ( value: number, offset: number, byteLength: number, noAssert?: boolean) => number;
method writeUInt16BE
writeUInt16BE: (value: number, offset: number, noAssert?: boolean) => number;
method writeUInt16LE
writeUInt16LE: (value: number, offset: number, noAssert?: boolean) => number;
method writeUInt32BE
writeUInt32BE: (value: number, offset: number, noAssert?: boolean) => number;
method writeUInt32LE
writeUInt32LE: (value: number, offset: number, noAssert?: boolean) => number;
method writeUInt8
writeUInt8: (value: number, offset: number, noAssert?: boolean) => number;
method writeUIntBE
writeUIntBE: ( value: number, offset: number, byteLength: number, noAssert?: boolean) => number;
method writeUIntLE
writeUIntLE: ( value: number, offset: number, byteLength: number, noAssert?: boolean) => number;
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (2)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/safe-buffer
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/safe-buffer)
- HTML<a href="https://www.jsdocs.io/package/safe-buffer"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2109 ms. - Missing or incorrect documentation? Open an issue for this package.