Commit 5250a462 authored by Linshizhi's avatar Linshizhi

channel update

parent b175c76d
......@@ -340,27 +340,32 @@ export class Channel {
}
#readDataBlks(size) {
let buffer = undefined;
let endPos = this.#endPos - 1;
let buffer = new Uint8Array(0);
this.#writePointerCache = this.#getWritePointer();
if (this.dataSize() < size)
return buffer;
return new Uint8Array(0);
let blksRequired = Math.floor(size / this.#blockSize);
if (blksRequired == 0) {
return buffer;
return new Uint8Array(0);
}
buffer = new Uint8Array(blksRequired * this.#blockSize);
if (this.#readPointerCache >= this.#writePointerCache) {
let spaceBetweenEnd = endPos - this.#readPointerCache;
let blks = Math.floor(spaceBetweenEnd / this.#blockSize);
if (blks >= blksRequired) {
buffer = new Uint8Array(blksRequired * this.#blockSize);
buffer.set(this.#buffer.subarray(
this.#readPointerCache, this.#readPointerCache+(blksRequired*this.#blockSize)))
return buffer;
} else {
/* Two step to read datas */
}
} else if (this.#readPointerCache < this.#writePointerCache) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment