Skip to content

Commit

Permalink
Merge branch 'feat/expect-object-containing' of github.com:eryue0220/…
Browse files Browse the repository at this point in the history
…deno_std into feat/expect-object-containing

* 'feat/expect-object-containing' of github.com:eryue0220/deno_std:
  BREAKING(io): remove `StringReader` (denoland#6062)
  BREAKING(io): remove `StringWriter` (denoland#6061)
  BREAKING(io): remove `MultiReader` (denoland#6059)
  BREAKING(io): remove `LimitedReader` (denoland#6058)
  chore: fix heading level in Releases.md (denoland#6044)
  BREAKING(io): remove `readDelim()` (denoland#6052)
  BREAKING(io): remove `BufWriter` (denoland#6057)
  BREAKING(io): remove `BufReader` (denoland#6056)
  • Loading branch information
eryue0220 committed Sep 26, 2024
2 parents f74b864 + 9f3cd4a commit 8c69042
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 2,429 deletions.
2 changes: 1 addition & 1 deletion Releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
- fix(http): make `file-server` work on Deno Deploy (#6033)
- fix(http): use non-locale-sensitive string methods for comparison (#6029)

### @std/internal 1.0.4 (patch)
#### @std/internal 1.0.4 (patch)

- chore: bump to internal@1.0.4 (#6020)

Expand Down
15 changes: 14 additions & 1 deletion archive/_common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import { PartialReadError } from "@std/io/buf-reader";
import type { Reader } from "@std/io/types";

/**
Expand Down Expand Up @@ -173,6 +172,20 @@ export const USTAR_STRUCTURE = [
*/
export type UstarFields = (typeof USTAR_STRUCTURE)[number]["field"];

/**
* Thrown when a read from a stream fails to read the
* requested number of bytes.
*/
class PartialReadError extends Error {
partial: Uint8Array;

constructor(partial: Uint8Array) {
super("Encountered UnexpectedEof, data only partially read");
this.name = this.constructor.name;
this.partial = partial;
}
}

export async function readBlock(
reader: Reader,
p: Uint8Array,
Expand Down
24 changes: 24 additions & 0 deletions archive/_multi_reader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import type { Reader } from "@std/io/types";

export class MultiReader implements Reader {
readonly #readers: Reader[];
#currentIndex = 0;

constructor(readers: Reader[]) {
this.#readers = [...readers];
}

async read(p: Uint8Array): Promise<number | null> {
const r = this.#readers[this.#currentIndex];
if (!r) return null;
const result = await r.read(p);
if (result === null) {
this.#currentIndex++;
return 0;
}
return result;
}
}
2 changes: 1 addition & 1 deletion archive/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
USTAR_STRUCTURE,
} from "./_common.ts";
import type { Reader } from "@std/io/types";
import { MultiReader } from "@std/io/multi-reader";
import { MultiReader } from "./_multi_reader.ts";
import { Buffer } from "@std/io/buffer";
import { HEADER_LENGTH } from "./_common.ts";

Expand Down
Loading

0 comments on commit 8c69042

Please sign in to comment.