UNPKG

tedious

Version:

A TDS driver, for connecting to MS SQLServer databases.

85 lines (84 loc) • 3.16 kB
export type Encoding = 'utf8' | 'ucs2' | 'ascii'; /** * A write-side buffer list. * * Bytes are appended through the `write*` methods, and taken out again * either as a single buffer (`data`, `slice`) or as a list of chunks * (`getBuffers`, `consume`). Small pieces are coalesced into chunks of at * most `CHUNK_SIZE` bytes. Buffers of at least `CHUNK_SIZE` bytes written * through `writeBuffer` are referenced rather than copied, so that large * values cost no extra memory. (The caller must therefore not modify such * buffers until they have been consumed.) * * The consumer side (`length`, `getBuffers`, `consume`, `slice`) mirrors * that of `bl`'s `BufferList`. */ declare class WritableTrackingBuffer { /** * The size of the chunks a `WritableTrackingBuffer` produces, and the size * from which written buffers are referenced rather than copied. */ static readonly CHUNK_SIZE: number; /** * The number of bytes appended and not yet consumed. */ length: number; private _bufs; private _open; private _pos; constructor(); /** * All appended and not yet consumed bytes as a single buffer. * * When everything fits into a single chunk this is a view of that chunk * rather than a copy. The returned buffer must not be modified. */ get data(): Buffer; private _seal; private _ensure; /** * The chunks holding all appended and not yet consumed bytes. * * The returned array is the list's own: later appends can add chunks to * it. `consume` does not modify it, so taking the chunks and consuming * them right away yields a stable snapshot. */ getBuffers(): Buffer[]; /** * Discards the given number of bytes from the front of the list. */ consume(bytes: number): this; /** * Copies all appended and not yet consumed bytes into a new buffer. */ slice(): Buffer; writeUInt8(value: number): void; writeUInt16LE(value: number): void; writeUShort(value: number): void; writeUInt16BE(value: number): void; writeUInt24LE(value: number): void; writeUInt32LE(value: number): void; writeBigInt64LE(value: bigint): void; writeInt64LE(value: number): void; writeUInt64LE(value: number): void; writeBigUInt64LE(value: bigint): void; writeUInt32BE(value: number): void; writeUInt40LE(value: number): void; writeInt8(value: number): void; writeInt16LE(value: number): void; writeInt16BE(value: number): void; writeInt32LE(value: number): void; writeInt32BE(value: number): void; writeFloatLE(value: number): void; writeDoubleLE(value: number): void; writeString(value: string, encoding: Encoding): void; writeBVarchar(value: string, encoding: Encoding): void; writeUsVarchar(value: string, encoding: Encoding): void; writeUsVarbyte(value: Buffer): void; /** * Appends a buffer. Buffers of at least `CHUNK_SIZE` bytes are referenced * rather than copied, and must not be modified until consumed. */ writeBuffer(value: Buffer): void; } export default WritableTrackingBuffer;