diff --git a/binary_to_json.ts b/binary_to_json.ts index b6f0077..46e09d0 100644 --- a/binary_to_json.ts +++ b/binary_to_json.ts @@ -63,7 +63,7 @@ export class BinaryToJSON { private getValue(br: BinaryReader, format:{}) : number | null | string { const [key, val] = Object.entries(format)[0]; - if (key === "__reserve") { + if (key === "__reserve" || key === "__skip") { br.seek(br.position + Number(val)); return null; } diff --git a/test.ts b/test.ts index 523601f..0a1ffed 100644 --- a/test.ts +++ b/test.ts @@ -132,17 +132,34 @@ Deno.test( assertEquals(0x0001020304050607, data['dat']); }, ); -/* Deno.test( "complex dat", function(): void { - const file = Deno.openSync("xxx.DAT"); + /* + const file = Deno.openSync("XXX.DAT"); const buffer = Deno.readAllSync(file); Deno.close(file.rid); const format = JSON.parse(Deno.readTextFileSync("prct_format.json")); const b2j = new BinaryToJSON(); const data: any = b2j.convert(buffer, format); - console.log(data); + //console.log(data); + */ }, ); -*/ + +Deno.test( + "skip bytes", + function(): void { + const buffer = new ArrayBuffer(4); + const arry = new Uint8Array(buffer); + arry[0] = 0x0D; + arry[1] = 0x0C; + arry[2] = 0x0B; + arry[3] = 0x0A; + const format = [{"__skip":2},{"dat":2}]; + const b2j = new BinaryToJSON(); + const data: any = b2j.convert(arry, format); + console.log(data); + assertEquals(0x0B0A, data['dat']); + }, +); \ No newline at end of file