- moved uint8array concat and split functions to their own files
- fixed an error in the cd command as a result of a previous improvement
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
function divideToChunks(data: Uint8Array): Uint8Array[] {
|
||||
const nChunks: number = Math.ceil(data.length / 1024);
|
||||
|
||||
const chunks: Uint8Array[] = [];
|
||||
for (let i = 0; i < nChunks; i++) {
|
||||
const start = 1024 * i;
|
||||
const end = 1024 * (i + 1);
|
||||
|
||||
chunks.push(data.slice(start, end));
|
||||
}
|
||||
|
||||
return chunks;
|
||||
}
|
||||
|
||||
test("divide to chunks", () => {
|
||||
const data: Uint8Array = new Uint8Array(2048);
|
||||
const result: Uint8Array[] = divideToChunks(data);
|
||||
expect(result.length).toEqual(2);
|
||||
});
|
||||
|
||||
test("divide to chunks", () => {
|
||||
const data: Uint8Array = new Uint8Array(2049);
|
||||
const result = divideToChunks(data);
|
||||
expect(result.length).toEqual(3);
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
import { splitUint8Array } from "@termos/util/concat";
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
test("divide to chunks", () => {
|
||||
const data: Uint8Array = new Uint8Array(2048);
|
||||
const result = splitUint8Array(data, 1024);
|
||||
expect(result.length).toEqual(2);
|
||||
});
|
||||
|
||||
test("divide to chunks", () => {
|
||||
const data: Uint8Array = new Uint8Array(2049);
|
||||
const result = splitUint8Array(data, 1024);
|
||||
expect(result.length).toEqual(3);
|
||||
});
|
||||
|
||||
test("divide to chunks", () => {
|
||||
const data: Uint8Array = new Uint8Array(2048);
|
||||
const result = splitUint8Array(data, 53);
|
||||
expect(result.length).toEqual(Math.ceil(2048 / 53));
|
||||
});
|
||||
Reference in New Issue
Block a user