Quark
#
Modules #
quark/actionquark/appquark/bubblesquark/bufferquark/checkboxquark/cssquark/ctrquark/dialogquark/eventquark/fontquark/fsquark/hashquark/httpquark/indexquark/jsonbquark/keyboardquark/mediaquark/navquark/netquark/osquark/pathquark/pkgquark/screenquark/stepperquark/storagequark/testquark/typesquark/utilquark/viewquark/windowquark/wsquark/_bufferquark/_commonquark/_eventquark/_extquark/_md5quark/_sha1quark/_sha256quark/_utilquark/_watching
Quark v1.3.0 Documentation
Table of Contents
-
quark/buffer
- Encoding
-
Class: Buffer
- Buffer
- buffer.copy(target,targetStart?,sourceStart?,sourceEnd?)
- buffer.slice(start?,end?)
- buffer.subarray(begin?,end?)
- buffer.toJSON()
- buffer.write(source,offset?)
- buffer.compare(target,start?,end?,thisStart?,thisEnd?)
- buffer.equals(b)
- buffer.toString(encoding?,start?,end?)
- buffer.readInt8(offset?)
- buffer.readUInt8(offset?)
- Zero
- alloc(size,initFill?)
- isTypedArray(arr)
- isUint8Array(arr)
- isBuffer(arr)
- compare(a,b)
- toString(src,encoding?,start?,end?)
- fromString(str,targetEn?)
- from(from,encoding?)
- from(from)
- from(from,byteOffset?,length?)
- from(from,mapFn?)
- concat(list,length?)
quark/buffer #
Encoding #
All encoding algorithms of string
@typeEncoding="binary"|"ascii"|"base64"|"hex"|"utf-8"|"utf8"|"utf-16"|"utf16"|"ucs4"
Class: Buffer #
Buffer #
This class represents a binary buffer.
@extendsUint8Array
buffer.copy(target,targetStart?,sourceStart?,sourceEnd?) #
Copy current buffer data to the target buffer.
@paramtarget:ArrayBufferViewThe target buffer to copy data into.@paramtargetStart?:UintThe starting index in the target buffer, Default is 0.@paramsourceStart?:UintThe starting index in the source buffer, Default is 0.@paramsourceEnd?:UintThe ending index in the source buffer, Default is the length of the source buffer.@returnUintThe number of bytes copied.@throws{TypeError} If the target is not a valid typed array.@throws{RangeError} If the target start index is out of range.@throws{RangeError} If the source start or end index is out of range.
For example:
const source = new Buffer([1, 2, 3, 4, 5]);
const target = new Buffer(3);
const bytesCopied = source.copy(target, 0, 1, 4);
console.log(bytesCopied); // Outputs: 3
console.log(target); // Outputs: Uint8Array(3) [2, 3, 4]
buffer.slice(start?,end?) #
slice the buffer data into a new buffer, shared memory with the original buffer.
buffer.subarray(begin?,end?) #
subarray the buffer data into a new buffer, shared memory with the original buffer.
buffer.toJSON() #
JSON representation of the buffer.
@return
buffer.write(source,offset?) #
writing data to self buffer.
buffer.compare(target,start?,end?,thisStart?,thisEnd?) #
Compare this buffer with another buffer or Uint8Array.
@paramtarget:Uint8ArrayThe target buffer or Uint8Array to compare with.@paramstart?:UintThe starting index in the target buffer, Default is 0.@paramend?:UintThe ending index in the target buffer, Default is the length of the target buffer.@paramthisStart?:UintThe starting index in this buffer, Default is 0.@paramthisEnd?:UintThe ending index in this buffer, Default is the length of this buffer.@returnIntReturns 0 if the buffers are equal, a negative number if this buffer is less than the target, or a positive number if this buffer is greater than the target.@throws{TypeError} If the target is not a valid typed array.@throws{RangeError} If the start or end indices are out of range.
For example:
const buf1 = new Buffer([1, 2, 3]);
const buf2 = new Buffer([1, 2, 3, 4]);
console.log(buf1.compare(buf2)); // Outputs: -1 (buf1 is less than buf2)
console.log(buf2.compare(buf1)); // Outputs: 1 (buf2 is greater than buf1)
console.log(buf1.compare(buf1)); // Outputs: 0 (buf1 is equal to itself)
buffer.equals(b) #
Check if this buffer is equal to another buffer or Uint8Array.
@paramb:Uint8ArrayThe buffer or Uint8Array to compare with.@returnbooleanReturns true if the buffers are equal, false otherwise.@throws{TypeError} If the argument is not a valid Uint8Array.
For example:
const buf1 = new Buffer([1, 2, 3]);
const buf2 = new Buffer([1, 2, 3]);
const buf3 = new Buffer([4, 5, 6]);
console.log(buf1.equals(buf2)); // Outputs: true (buf1 is equal to buf2)
console.log(buf1.equals(buf3)); // Outputs: false (buf1 is not equal to buf3)
buffer.toString(encoding?,start?,end?) #
Convert the buffer to a string using the specified encoding.
@paramencoding?:EncodingThe encoding to use, Default is 'utf8'.@paramstart?:UintThe starting index, Default is 0.@paramend?:UintThe ending index, Default is the length of the buffer.@returnstringThe string representation of the buffer.
For example:
const buf = new Buffer([72, 101, 108, 108,111]);
console.log(buf.toString('utf8')); // Outputs: Hello
buffer.readInt8(offset?) #
Read int8 from the buffer at the specified offset.
buffer.readUInt8(offset?) #
Read uint8 from the buffer at the specified offset.
Zero #
Zero buffer
@constZero:
alloc(size,initFill?) #
Alloc new buffer
isTypedArray(arr) #
Tests whether it is a typed array
@paramarr:any@returnboolean
isUint8Array(arr) #
Tests whether it is a Uint8Array
@paramarr:any@returnboolean
isBuffer(arr) #
Tests whether it is a buffer data type
@paramarr:any@returnboolean
compare(a,b) #
Compare sizes of two buffers
@parama:Uint8Array@paramb:Uint8Array@returnInt
toString(src,encoding?,start?,end?) #
Decode data into a string using the specified algorithm
@paramsrc:Uint8Array@paramencoding?:Encoding@paramstart?:Uint@paramend?:Uint@returnstring
fromString(str,targetEn?) #
Specify the algorithm to encode the string and return the encoded data
@paramstr:stringThe string to encode.@paramtargetEn?:EncodingOptional, the encoding algorithm to use, Default is 'utf8'.@returnUint8ArrayA Uint8Array containing the encoded data.
For example:
const encoded = fromString("Hello, World!", "utf8");
console.log(encoded); // Outputs: Uint8Array(13) [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]
from(from,encoding?) #
From string create a buffer
@paramfrom:stringa string to create a buffer from@paramencoding?:EncodingOptional, this specifies the encoding to use.@returnBuffer
from(from) #
From ArrayBufferView create a buffer
@paramfrom:ArrayBufferViewa TypedArray or DataView to create a buffer from@returnBuffer
from(from,byteOffset?,length?) #
From ArrayBufferLike create a buffer
@paramfrom:ArrayBufferLikean ArrayBuffer or SharedArrayBuffer to create a buffer from@parambyteOffset?:UintOptional, the offset in bytes to start from, Default is 0.@paramlength?:UintOptional, the length in bytes of the buffer, Default is the remaining length of the ArrayBuffer.
For example:
const buffer = from(new ArrayBuffer(10), 0, 10);
console.log(buffer.byteLength); // Outputs: 10
@returnBuffer
from(from,mapFn?) #
From Iterable or ArrayLike create a buffer
@paramfrom:Iterable<Int>|ArrayLike<Int> an iterable or array-like object to create a buffer from@parammapFn?:MapFnOptional, a mapping function to apply to each element.
For example:
const buffer = from([1, 2, 3, 4], (v, k) => v * 2);
console.log(buffer); // Outputs: Uint8Array(4) [2, 4, 6, 8]
@returnBuffer
concat(list,length?) #
Concat multiple buffers into a new buffer
@paramlist:ArrayLike<Int>[]An array of byte arrays to concatenate.@paramlength?:UintOptional, the total length of the new buffer. If not provided,
it will be calculated based on the lengths of the byte arrays in the list.@returnBufferA new Buffer containing the concatenated data.
For example:
const buffer1 = new Buffer([1, 2, 3]);
const buffer2 = new Buffer([4, 5, 6]);
const concatenated = concat([buffer1, buffer2]);
console.log(concatenated); // Outputs: Uint8Array(6) [1, 2, 3, 4, 5, 6]
@throws{TypeError} If the provided list is not an array-like object or if
any of the elements in the list are not of typeUint8ArrayorBuffer.@throws{RangeError} If the specified length is negative.@throws{Error} If the concatenation fails for any reason.