diff options
Diffstat (limited to 'std/encoding')
-rw-r--r-- | std/encoding/README.md | 4 | ||||
-rw-r--r-- | std/encoding/binary.ts | 20 | ||||
-rw-r--r-- | std/encoding/csv.ts | 14 |
3 files changed, 16 insertions, 22 deletions
diff --git a/std/encoding/README.md b/std/encoding/README.md index e6604c605..7d9c89117 100644 --- a/std/encoding/README.md +++ b/std/encoding/README.md @@ -17,8 +17,8 @@ Available Functions: ```typescript sizeof(dataType: RawTypes): number getNBytes(r: Deno.Reader, n: number): Promise<Uint8Array> -varnum(b: Uint8Array, o: VarnumOptions = {}): number | Deno.EOF -varbig(b: Uint8Array, o: VarbigOptions = {}): bigint | Deno.EOF +varnum(b: Uint8Array, o: VarnumOptions = {}): number | null +varbig(b: Uint8Array, o: VarbigOptions = {}): bigint | null putVarnum(b: Uint8Array, x: number, o: VarnumOptions = {}): number putVarbig(b: Uint8Array, x: bigint, o: VarbigOptions = {}): number readVarnum(r: Deno.Reader, o: VarnumOptions = {}): Promise<number> 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": diff --git a/std/encoding/csv.ts b/std/encoding/csv.ts index 711e27772..ae86e25bb 100644 --- a/std/encoding/csv.ts +++ b/std/encoding/csv.ts @@ -64,12 +64,12 @@ async function readRecord( Startline: number, reader: BufReader, opt: ReadOptions = { comma: ",", trimLeadingSpace: false } -): Promise<string[] | Deno.EOF> { +): Promise<string[] | null> { const tp = new TextProtoReader(reader); const lineIndex = Startline; let line = await readLine(tp); - if (line === Deno.EOF) return Deno.EOF; + if (line === null) return null; if (line.length === 0) { return []; } @@ -147,7 +147,7 @@ async function readRecord( // Hit end of line (copy all data so far). recordBuffer += line; const r = await readLine(tp); - if (r === Deno.EOF) { + if (r === null) { if (!opt.lazyQuotes) { quoteError = ERR_QUOTE; break parseField; @@ -182,13 +182,13 @@ async function readRecord( } async function isEOF(tp: TextProtoReader): Promise<boolean> { - return (await tp.r.peek(0)) === Deno.EOF; + return (await tp.r.peek(0)) === null; } -async function readLine(tp: TextProtoReader): Promise<string | Deno.EOF> { +async function readLine(tp: TextProtoReader): Promise<string | null> { let line: string; const r = await tp.readLine(); - if (r === Deno.EOF) return Deno.EOF; + if (r === null) return null; line = r; // For backwards compatibility, drop trailing \r before EOF. @@ -226,7 +226,7 @@ export async function readMatrix( for (;;) { const r = await readRecord(lineIndex, reader, opt); - if (r === Deno.EOF) break; + if (r === null) break; lineResult = r; lineIndex++; // If fieldsPerRecord is 0, Read sets it to |