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

write_file cannot write files with ".zip" extension #1247

Open
MilesMcBain opened this issue Jul 27, 2021 · 4 comments
Open

write_file cannot write files with ".zip" extension #1247

MilesMcBain opened this issue Jul 27, 2021 · 4 comments
Labels
feature a feature request or enhancement

Comments

@MilesMcBain
Copy link

write_file cannot write .zip files. The issue seems to be in this switch statement in standardise_path:

switch(compression,

Where the other zip functions create connections, readr::zipfile attempts to decompress the file file, which doesn't exist because we're trying to write it.

readr::write_file(charToRaw(letters), "./test.zip")
#> Error in utils::unzip(path, list = TRUE): zip file './test.zip' cannot be opened

Created on 2021-07-27 by the reprex package (v2.0.0)

@jimhester
Copy link
Collaborator

jimhester commented Aug 6, 2021

Base R does not support writing to zip files from a connection. e.g. there is no write equivalent to unz().

However you can now use the archive package to do this.

readr::write_file(paste0(letters, collapse = ""), archive::archive_write("letters.zip", "letters"))

@MilesMcBain
Copy link
Author

Ah sorry if I was unclear. I don't want to zip data. I have the raw data representing a zip file in the body of a http request. I can't write that to a .zip file on disk.

My work around was to write it with a different extension, then change the extension to zip after.

@jimhester jimhester added the feature a feature request or enhancement label Sep 22, 2021
@sbearrows sbearrows assigned sbearrows and unassigned sbearrows Apr 4, 2022
@minemR
Copy link

minemR commented Sep 5, 2023

My work around was to use:

readr:::write_file_raw_(x, connection)

I guess that is quite bad, because the unexported function could change or be removed in next release...

@jimhester
Copy link
Collaborator

jimhester commented Sep 14, 2023

Perhaps just use base::writeBin() or possibly brio::write_file_raw() if you want to write bytes to disk and not do any transformations of the data.

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

No branches or pull requests

4 participants