-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52e870b
commit 2de98e3
Showing
7 changed files
with
69 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,9 @@ | |
"version": "4.0.1", | ||
"exports": "./mod.ts", | ||
"imports": { | ||
"$std/": "https://deno.land/[email protected]/", | ||
"@dldc/erreur": "jsr:@dldc/erreur@^7.1.1", | ||
"@dldc/file": "jsr:@dldc/file@^2.0.1", | ||
"@std/expect": "jsr:@std/expect@^1.0.7", | ||
"sql.js": "npm:sql.js@^1.10.3" | ||
}, | ||
"tasks": { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
import { expect } from "$std/expect/mod.ts"; | ||
import { Buffer } from "node:buffer"; | ||
import { expect } from "@std/expect"; | ||
import { prepare } from "../mod.ts"; | ||
import { arrayBufferEqual } from "./utils/arrayBufferEqual.ts"; | ||
import { data } from "./utils/data.ts"; | ||
|
||
Deno.test("checksums", () => { | ||
const testData1 = data.buffer.slice(0); | ||
const blockSize = 16; | ||
const doc1 = Buffer.from(prepare(testData1, blockSize)); | ||
const doc1 = prepare(testData1, blockSize); | ||
|
||
const testData2 = data.buffer.slice(0); | ||
const doc2 = Buffer.from(prepare(testData2, blockSize)); | ||
const doc2 = prepare(testData2, blockSize); | ||
|
||
expect(doc1.equals(doc2)).toBe(true); | ||
expect(arrayBufferEqual(doc1, doc2)).toBe(true); | ||
|
||
// change data in first block | ||
new Uint8Array(testData2)[0]++; | ||
const doc3 = Buffer.from(prepare(testData2, blockSize)); | ||
const doc3 = prepare(testData2, blockSize); | ||
|
||
expect(doc1.equals(doc3)).toBe(false); | ||
expect(arrayBufferEqual(doc1, doc3)).toBe(false); | ||
|
||
// adler32 is different for first block | ||
expect(doc1.slice(8, 12).equals(doc3.slice(8, 12))).toBe(false); | ||
expect(arrayBufferEqual(doc1.slice(8, 12), doc3.slice(8, 12))).toBe(false); | ||
// md5 is different for first block | ||
expect(doc1.slice(12, 28).equals(doc3.slice(12, 28))).toBe(false); | ||
expect(arrayBufferEqual(doc1.slice(12, 28), doc3.slice(12, 28))).toBe(false); | ||
// rest is the same | ||
expect(doc1.slice(28).equals(doc3.slice(28))).toBe(true); | ||
expect(arrayBufferEqual(doc1.slice(28), doc3.slice(28))).toBe(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export function arrayBufferEqual(a: ArrayBuffer, b: ArrayBuffer): boolean { | ||
if (a.byteLength !== b.byteLength) { | ||
return false; | ||
} | ||
const aView = new Uint8Array(a); | ||
const bView = new Uint8Array(b); | ||
for (let i = 0; i < a.byteLength; i++) { | ||
if (aView[i] !== bView[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |