Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING(io): remove copyN() #5999

Merged
merged 3 commits into from
Sep 25, 2024
Merged

BREAKING(io): remove copyN() #5999

merged 3 commits into from
Sep 25, 2024

Conversation

iuioiua
Copy link
Contributor

@iuioiua iuioiua commented Sep 17, 2024

What's changed

copyN() has been removed from @std/io.

Motivation

This change was made to help push users towards using the Streams API and @std/streams, and make design decisions about which APIs easier.

Migration guide

To migrate, use ByteSliceStream, setting start to 0 and end to 1 less than that of size in concatN(), then pipe to the destination writable stream.

- import { copyN } from "@std/io/copy-n";
+ import { ByteSliceStream } from "@std/streams/byte-slice-stream";

  const source = await Deno.open("README.md");

- await copyN(source, Deno.stdout, 10);
+ await source.readable
+   .pipeThrough(new ByteSliceStream(0, 9))
+   .pipeTo(Deno.stdout.writable);

Related

Towards #5989

@github-actions github-actions bot added the io label Sep 17, 2024
Copy link

codecov bot commented Sep 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.29%. Comparing base (05b6d7e) to head (3703431).
Report is 41 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5999   +/-   ##
=======================================
  Coverage   96.29%   96.29%           
=======================================
  Files         493      492    -1     
  Lines       39530    39497   -33     
  Branches     5833     5828    -5     
=======================================
- Hits        38065    38035   -30     
+ Misses       1423     1420    -3     
  Partials       42       42           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@iuioiua iuioiua closed this Sep 18, 2024
@iuioiua iuioiua reopened this Sep 25, 2024
@iuioiua iuioiua marked this pull request as ready for review September 25, 2024 02:07
@iuioiua iuioiua requested a review from kt3k as a code owner September 25, 2024 02:07
@iuioiua iuioiua enabled auto-merge (squash) September 25, 2024 02:18
@kt3k kt3k changed the title BREAKING(io/unstable): remove copyN() BREAKING(io): remove copyN() Sep 25, 2024
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM

@iuioiua iuioiua merged commit 548d254 into main Sep 25, 2024
16 checks passed
@iuioiua iuioiua deleted the remove-copy-n-2 branch September 25, 2024 03:50
@kt3k
Copy link
Member

kt3k commented Sep 25, 2024

The user might need ReadableStreamBYOBReader#read for the replacement if they need more accurate translation. readable.pipeThrough(new ByteSliceStream(0, 9)) consumes the entire readable stream, while copyN doesn't consume the entire reader. (The reader is paused at the end of copied bytes, and can be resumed from there)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants