summaryrefslogtreecommitdiff
path: root/std/encoding/binary.ts
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-04-28 17:40:43 +0100
committerGitHub <noreply@github.com>2020-04-28 12:40:43 -0400
commit678313b17677e012ba9a07aeca58af1aafbf4e8c (patch)
treee48e25b165a7d6d566095442448f2e36fa09c561 /std/encoding/binary.ts
parent47c2f034e95696a47770d60aec1362501e7f330d (diff)
BREAKING: Remove Deno.EOF, use null instead (#4953)
Diffstat (limited to 'std/encoding/binary.ts')
-rw-r--r--std/encoding/binary.ts20
1 files changed, 7 insertions, 13 deletions
diff --git a/std/encoding/binary.ts b/std/encoding/binary.ts
index cd338703b..dd9c26243 100644
--- a/std/encoding/binary.ts
+++ b/std/encoding/binary.ts
@@ -51,19 +51,16 @@ export async function getNBytes(
): Promise<Uint8Array> {
const scratch = new Uint8Array(n);
const nRead = await r.read(scratch);
- if (nRead === Deno.EOF || nRead < n) throw new Deno.errors.UnexpectedEof();
+ if (nRead === null || nRead < n) throw new Deno.errors.UnexpectedEof();
return scratch;
}
/** Decode a number from `b`, and return it as a `number`. Data-type defaults to `int32`.
- * Returns `EOF` if `b` is too short for the data-type given in `o`. */
-export function varnum(
- b: Uint8Array,
- o: VarnumOptions = {}
-): number | Deno.EOF {
+ * Returns `null` if `b` is too short for the data-type given in `o`. */
+export function varnum(b: Uint8Array, o: VarnumOptions = {}): number | null {
o.dataType = o.dataType ?? "int32";
const littleEndian = (o.endian ?? "big") === "little" ? true : false;
- if (b.length < sizeof(o.dataType)) return Deno.EOF;
+ if (b.length < sizeof(o.dataType)) return null;
const view = new DataView(b.buffer);
switch (o.dataType) {
case "int8":
@@ -86,14 +83,11 @@ export function varnum(
}
/** Decode an integer from `b`, and return it as a `bigint`. Data-type defaults to `int64`.
- * Returns `EOF` if `b` is too short for the data-type given in `o`. */
-export function varbig(
- b: Uint8Array,
- o: VarbigOptions = {}
-): bigint | Deno.EOF {
+ * Returns `null` if `b` is too short for the data-type given in `o`. */
+export function varbig(b: Uint8Array, o: VarbigOptions = {}): bigint | null {
o.dataType = o.dataType ?? "int64";
const littleEndian = (o.endian ?? "big") === "little" ? true : false;
- if (b.length < sizeof(o.dataType)) return Deno.EOF;
+ if (b.length < sizeof(o.dataType)) return null;
const view = new DataView(b.buffer);
switch (o.dataType) {
case "int8":