Skip to content

feat(io): re-introduce IO functions - #4128

Merged
iuioiua merged 9 commits into
mainfrom
reintroduce-io
Jan 12, 2024
Merged

feat(io): re-introduce IO functions#4128
iuioiua merged 9 commits into
mainfrom
reintroduce-io

Conversation

@iuioiua

@iuioiua iuioiua commented Jan 8, 2024

Copy link
Copy Markdown
Contributor

This change re-introduces some of the previously deprecated and I/O-related functions and types. In short, these functions are moved from std/streams to std/io, which makes a lot more sense, in my opinion. These changes also include a few minor non-breaking (hopefully) tweaks.

The refreshed std/io API aims to be as basic and minimal as possible while still covering the basic I/O modalities such as reading (readAll()), writing (writeAll()) and transferring (copy()), as well as conversion utilities to the Streams API's interfaces for more advanced use. E.g. TextLineStream(). There's an argument to be made that storage (Buffer) should be included in these primary modalities, but users may be fine without it.

Closes #4120
Towards denoland/deno#9795

Comment thread archive/tar_test.ts Outdated
Comment thread io/read_all.ts
* file.close();
* ```
*/
export async function readAll(reader: Reader): Promise<Uint8Array> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function differs from readAll() from std/streams in that it doesn't depend on Buffer() from std/io. It's simpler, only relying on concat(). This should be a non-breaking change.

Comment thread io/read_all.ts
*
* @example
* ```ts
* import { readAll } from "https://deno.land/std@$STD_VERSION/io/read_all.ts";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Buffer() is not imported here as it's deprecated.

Comment thread io/read_all_test.ts
Deno.test("readAll()", async () => {
const testBytes = init();
assert(testBytes);
const reader = new Buffer(testBytes.buffer);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We rely on Buffer() here but should work on removing that dependency in the future (in a PR).

Comment thread io/to_readable_stream.ts
* const fileStream = toReadableStream(file);
* ```
*/
export function toReadableStream(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: renamed from readableStreamfFromReader().

Comment thread io/to_writable_stream.ts
* .pipeTo(toWritableStream(file));
* ```
*/
export function toWritableStream(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: renamed from writableStreamFromWriter().

@iuioiua
iuioiua marked this pull request as ready for review January 9, 2024 21:47
@iuioiua
iuioiua requested a review from crowlKats as a code owner January 9, 2024 21:47
@iuioiua
iuioiua marked this pull request as draft January 9, 2024 23:02
@iuioiua
iuioiua marked this pull request as ready for review January 9, 2024 23:28
@iuioiua
iuioiua requested a review from kt3k January 9, 2024 23:28
Comment thread streams/copy.ts
* {@linkcode ReadableStream.pipeTo} instead.
* @deprecated (will be removed in 0.214.0) Import from {@link https://deno.land/std/io/copy.ts} instead.
*/
export async function copy(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: a copySync() could be implemented. But there's never been any demand for it. I also wonder whether there's demand for readAllSync() and writeAllSync().

We could also name this copyAll() to align it with readAll() and writeAll().

@kt3k kt3k left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

suggestion: re-consider the deprecation of some IO-related APIs

2 participants