Skip to content

Read archive in chunks when publishing archive to registry #6979

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

spqw
Copy link
Contributor

@spqw spqw commented Oct 6, 2023

Add function to read archive in chunks when publishing archive to registry

Motivation:

This helps with memory efficiency and performance for large files.
This is implementing a TODO.

Modifications:

Before: The archive is read with readFileContents, loading the entire file in memory
Modification: The archive is read with a new function called readFileInChunks, using an InputStream.

Result:

The archive is read in chunks.

@spqw spqw force-pushed the package-registry-read-archive-in-chunks branch from 7c61991 to 264170b Compare October 6, 2023 21:50
@spqw spqw changed the title Add readFileInChunks Read archive in chunks when publishing archive to registry Oct 6, 2023
/// Get the contents of a file without loading all of it in memory
///
/// - Returns: The file contents as Data, or nil if missing
func readFileInChunks(path: AbsolutePath, bufferSize: Int = 1024) -> Data? {
Copy link
Contributor

@MaxDesiatov MaxDesiatov Oct 8, 2023

Choose a reason for hiding this comment

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

Sorry, I'm not sure I understand what this is trying to achieve. How exactly would this prevent reading the whole file into memory if the resulting Data value contains the whole file in memory due to the fact that all of the chunks are appended to it to form one huge Data buffer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're totally right.
My bad, this is actually far from being ready for review.
Marking it as a draft for now if that's ok.

@MaxDesiatov
Copy link
Contributor

Hi @spqw, would you be interested in addressing the PR review provided above?

@spqw spqw marked this pull request as draft November 9, 2023 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants