Commit 5250a462 authored by Linshizhi's avatar Linshizhi

channel update

parent b175c76d
...@@ -340,27 +340,32 @@ export class Channel { ...@@ -340,27 +340,32 @@ export class Channel {
} }
#readDataBlks(size) { #readDataBlks(size) {
let buffer = undefined;
let endPos = this.#endPos - 1; let endPos = this.#endPos - 1;
let buffer = new Uint8Array(0);
this.#writePointerCache = this.#getWritePointer(); this.#writePointerCache = this.#getWritePointer();
if (this.dataSize() < size) if (this.dataSize() < size)
return buffer; return new Uint8Array(0);
let blksRequired = Math.floor(size / this.#blockSize); let blksRequired = Math.floor(size / this.#blockSize);
if (blksRequired == 0) { if (blksRequired == 0) {
return buffer; return new Uint8Array(0);
} }
buffer = new Uint8Array(blksRequired * this.#blockSize);
if (this.#readPointerCache >= this.#writePointerCache) { if (this.#readPointerCache >= this.#writePointerCache) {
let spaceBetweenEnd = endPos - this.#readPointerCache; let spaceBetweenEnd = endPos - this.#readPointerCache;
let blks = Math.floor(spaceBetweenEnd / this.#blockSize); let blks = Math.floor(spaceBetweenEnd / this.#blockSize);
if (blks >= blksRequired) { if (blks >= blksRequired) {
buffer = new Uint8Array(blksRequired * this.#blockSize);
buffer.set(this.#buffer.subarray( buffer.set(this.#buffer.subarray(
this.#readPointerCache, this.#readPointerCache+(blksRequired*this.#blockSize))) this.#readPointerCache, this.#readPointerCache+(blksRequired*this.#blockSize)))
return buffer;
} else { } else {
/* Two step to read datas */
} }
} else if (this.#readPointerCache < this.#writePointerCache) { } 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