Added a very complicated AsyncIterableReader class.
The class was already implemented in "https://deno.land/std@0.144.0/streams/conversion.ts". So, I litterally lost 1 day of work! I hate myself.
This commit is contained in:
1 parent
17a1b4bed3
commit
0d627c9051
125 files changed
+26943
-83
No files matched your search
+25
@@ -0,0 +1,25 @@
|
||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { type BufReader } from "./buf_reader.ts";
|
||||
import { readInt } from "./read_int.ts";
|
||||
|
||||
const MAX_SAFE_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
|
||||
|
||||
/**
|
||||
* Read big endian 64bit long from BufReader
|
||||
* @param buf
|
||||
*/
|
||||
export async function readLong(buf: BufReader): Promise<number | null> {
|
||||
const high = await readInt(buf);
|
||||
if (high === null) return null;
|
||||
const low = await readInt(buf);
|
||||
if (low === null) throw new Deno.errors.UnexpectedEof();
|
||||
const big = (BigInt(high) << 32n) | BigInt(low);
|
||||
// We probably should provide a similar API that returns BigInt values.
|
||||
if (big > MAX_SAFE_INTEGER) {
|
||||
throw new RangeError(
|
||||
"Long value too big to be represented as a JavaScript number.",
|
||||
);
|
||||
}
|
||||
return Number(big);
|
||||
}
|
||||
Reference in new issue
Block a user