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

Download at url with progress #154

Closed

Conversation

fillito
Copy link
Contributor

@fillito fillito commented Oct 12, 2024

Downloading large files can be problematic because the SMBClient.download(path: String) stores the whole file in memory, returning it as a Data object.

This PR adds a new SMBClient.download(path: String, localPath: URL, overwrite: Bool, progressHandler: (Double) -> Void) to allow downloading files while writing the chunks of data to disk progressively, resulting in lower memory consumption.

  • localPath accepts a file URL, following the existing API in SMBClient.upload(localPath: URL, remotePath path: String)
  • overwrite flag enables overwriting the file if it already exists. If the file does exist and the flag is set to false, the download method throws a CocoaError.fileWriteFileExists (this is the best error I could find. let me know if there's a better one)
  • progressHandler allows for download progress updates. It follows the existing progressHandler API in the upload function.

I've also added a test for the new method.

@kishikawakatsumi
Copy link
Owner

Merged by #156

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.

2 participants