GithubHelp home page GithubHelp logo

zip's Introduction

zip

Cross-Platform ‘zip’ Compression

R-CMD-check CRAN RStudio mirror downloads Codecov test coverage

Installation

Stable version:

install.packages("zip")

Development version:

pak::pak("r-lib/zip")

Usage

library(zip)

Creating ZIP files

zip() creates a new ZIP archive. (It overwrites the output file if it exists.) Simply supply all directories and files that you want to include in the archive.

It makes sense to change to the top-level directory of the files before archiving them, so that the files are stored using a relative path name.

zip("sources.zip", c("R", "src"))
file.info("sources.zip")
#>               size isdir mode               mtime               ctime
#> sources.zip 580179 FALSE  644 2023-04-17 13:49:31 2023-04-17 13:49:31
#>                           atime uid gid       uname grname
#> sources.zip 2023-04-17 13:49:31 501  20 gaborcsardi  staff

Directories are added recursively by default.

zip_append() is similar to zip(), but it appends files to an existing ZIP archive.

Listing ZIP files

zip_list() lists files in a ZIP archive. It returns a data frame:

zip_list("sources.zip")
#>                                                     filename compressed_size
#> 1                                                         R/               0
#> 2                                             R/assertions.R             151
#> 3                                                R/inflate.R             627
#> 4                                                R/process.R            1793
#> 5                                                  R/utils.R            1202
#> 6                                                    R/zip.R            3274
#> 7                                                       src/               0
#> 8                                                 src/init.c             367
#> 9                                                 src/init.o            1648
#> 10                                        src/install.libs.R             272
#> 11                                              src/Makevars             199
#> 12                                          src/Makevars.win             273
#> 13                                               src/miniz.c           55268
#> 14                                               src/miniz.h           18115
#> 15                                               src/miniz.o          120248
#> 16                                                src/rzip.c            2853
#> 17                                                src/rzip.o           10431
#> 18                                                src/tools/               0
#> 19                                        src/tools/cmdunzip           62958
#> 20                                      src/tools/cmdunzip.c             590
#> 21                                  src/tools/cmdunzip.dSYM/               0
#> 22                         src/tools/cmdunzip.dSYM/Contents/               0
#> 23               src/tools/cmdunzip.dSYM/Contents/Info.plist             304
#> 24               src/tools/cmdunzip.dSYM/Contents/Resources/               0
#> 25         src/tools/cmdunzip.dSYM/Contents/Resources/DWARF/               0
#> 26 src/tools/cmdunzip.dSYM/Contents/Resources/DWARF/cmdunzip           70680
#> 27                                          src/tools/cmdzip           63367
#> 28                                        src/tools/cmdzip.c            1066
#> 29                                    src/tools/cmdzip.dSYM/               0
#> 30                           src/tools/cmdzip.dSYM/Contents/               0
#> 31                 src/tools/cmdzip.dSYM/Contents/Info.plist             303
#> 32                 src/tools/cmdzip.dSYM/Contents/Resources/               0
#> 33           src/tools/cmdzip.dSYM/Contents/Resources/DWARF/               0
#> 34     src/tools/cmdzip.dSYM/Contents/Resources/DWARF/cmdzip           71098
#> 35                                           src/unixutils.c             724
#> 36                                           src/unixutils.o            4329
#> 37                                            src/winutils.c            1949
#> 38                                                 src/zip.c            2830
#> 39                                                 src/zip.h             808
#> 40                                                 src/zip.o           10541
#> 41                                                src/zip.so           66645
#>    uncompressed_size           timestamp permissions    crc32 offset
#> 1                  0 2023-04-17 10:58:10         755 00000000      0
#> 2                398 2023-04-17 10:20:40         644 7f73a9e4     32
#> 3               2174 2023-04-17 10:20:40         644 3b0fdb9e    243
#> 4               6585 2023-04-17 10:20:40         644 99447436    927
#> 5               3915 2023-04-17 10:58:10         644 e653bff7   2777
#> 6              10369 2023-04-17 10:51:34         644 4d620f14   4034
#> 7                  0 2023-04-17 10:20:46         755 00000000   7361
#> 8                962 2023-04-17 10:20:40         644 e1c62c7d   7395
#> 9               3744 2023-04-17 10:20:46         644 6da275de   7818
#> 10               587 2022-03-04 14:05:04         644 4f80df1a   9522
#> 11               525 2022-12-19 13:17:12         644 c8789e48   9858
#> 12               700 2022-03-04 14:05:04         644 373232f9  10115
#> 13            314933 2023-04-17 10:20:40         644 450881b2  10450
#> 14             66871 2023-04-17 10:20:40         644 6c5a6c1e  65775
#> 15            333800 2023-04-17 10:20:46         644 887d9996  83947
#> 16             10857 2023-04-17 10:20:40         644 a2c358b5 204252
#> 17             23448 2023-04-17 10:20:46         644 ea86cde3 207161
#> 18                 0 2023-04-17 10:20:46         755 00000000 217648
#> 19            228469 2023-04-17 10:20:46         755 57376bd5 217688
#> 20              1343 2022-03-04 14:05:04         644 1a6e34f1 280710
#> 21                 0 2023-04-17 09:50:00         755 00000000 281366
#> 22                 0 2023-04-17 09:50:00         755 00000000 281420
#> 23               637 2023-04-17 10:20:46         644 294928f0 281483
#> 24                 0 2023-04-17 09:50:00         755 00000000 281876
#> 25                 0 2023-04-17 09:50:00         755 00000000 281949
#> 26            177363 2023-04-17 10:20:46         644 9d6e0672 282028
#> 27            228627 2023-04-17 10:20:46         755 0aa7342d 352811
#> 28              2909 2022-03-04 14:05:04         644 bfb4d8f3 416240
#> 29                 0 2023-04-17 09:50:00         755 00000000 417370
#> 30                 0 2023-04-17 09:50:00         755 00000000 417422
#> 31               635 2023-04-17 10:20:46         644 c3375fb9 417483
#> 32                 0 2023-04-17 09:50:00         755 00000000 417873
#> 33                 0 2023-04-17 09:50:00         755 00000000 417944
#> 34            178267 2023-04-17 10:20:46         644 d905adc8 418021
#> 35              1944 2022-03-04 14:05:04         644 d38da4b6 489218
#> 36              9592 2023-04-17 10:20:46         644 f55ccd93 490003
#> 37              6880 2023-04-17 10:20:40         644 4f65da62 494393
#> 38             11643 2023-04-17 10:20:40         644 119a0ee7 496402
#> 39              2349 2023-04-17 08:32:08         644 92f80ead 499287
#> 40             25288 2023-04-17 10:20:46         644 b69779f4 500150
#> 41            247235 2023-04-17 10:20:46         755 2090ba35 510746

Uncompressing ZIP files

unzip() uncompresses a ZIP archive:

exdir <- tempfile()
unzip("sources.zip", exdir = exdir)
dir(exdir)
#> [1] "R"   "src"

Compressing and uncompressing in background processes

You can use the zip_process() and unzip_process() functions to create background zip / unzip processes. These processes were implemented on top of the processx::process class, so they are pollable.

License

MIT

zip's People

Contributors

ashesitr avatar batpigandme avatar chainsawriot avatar daattali avatar gaborcsardi avatar jbfagotfede39 avatar jefferis avatar jeroen avatar jimhester avatar m-muecke avatar qulogic avatar weshinsley avatar wibeasley avatar zeehio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

zip's Issues

Unzip when file conatins UTF-8 characters in R

I want to unzip folder and rename files from rhat folder in R.

My try with zip package:

zip::unzip("my.path", exdir = "mydocument")
unzip_files <- list.files("mydocument", full.names = TRUE)
for (j in seq_along(unzip_files)) {
  file.rename(unzip_files[j], "somefilename")
}

The problem is that files in zip document contains UTF-8 characters:

16900-19 odb. parcelacija katastar - službeno više uložaka, čl. 145.doc

but when unzipped the files looks like this:

16900-19 odb. parcelacija katastar - službeno viÅ¡e uložaka, Äl. 145

and I can't rename it beacuse it has this strange characters.

So I need to unzip folder but keep UTF-8 characters or somehow rename file with this strange chracters.

zipping MS office docs

Hi

With function zipr, I am unable to reproduce the zip files I was producing with zip. I am using it to zip MS office documents.

The following is producing a directory containing the office XML structure in dir_extract:

library(zip)

zip_list("test_zip.docx")

dir_extract <- tempfile()
unzip(zipfile = "test_zip.docx", exdir = dir_extract)

test_zip.docx

The following code will not produce a valid file (but the structure looks ok):

zipr(zipfile = "test_out_0.docx", files = list.files(dir_extract, full.names = TRUE), recurse = TRUE)
zip_list("test_out_0.docx")
                       filename compressed_size uncompressed_size           timestamp permissions
1                        _rels/               0                 0 2019-03-26 17:09:14         700
2                   _rels/.rels             233               590 1979-12-31 23:00:00         600
3           [Content_Types].xml             340              1312 1979-12-31 23:00:00         600
4                     docProps/               0                 0 2019-03-26 17:09:14         700
5              docProps/app.xml             357               709 1979-12-31 23:00:00         600
6             docProps/core.xml             359               749 1979-12-31 23:00:00         600
7                         word/               0                 0 2019-03-26 17:09:14         700
8                   word/_rels/               0                 0 2019-03-26 17:09:14         700
9  word/_rels/document.xml.rels             237               817 1979-12-31 23:00:00         600
10            word/document.xml             661              2562 1979-12-31 23:00:00         600
11           word/fontTable.xml             445              1419 1979-12-31 23:00:00         600
12            word/settings.xml             920              2604 1979-12-31 23:00:00         600
13              word/styles.xml            2563             28902 1979-12-31 23:00:00         600
14                  word/theme/               0                 0 2019-03-26 17:09:14         700
15        word/theme/theme1.xml            1703              8394 1979-12-31 23:00:00         600
16         word/webSettings.xml             288               655 1979-12-31 23:00:00         600

The following code will produce a valid file:

oldwd <- getwd()
setwd(dir_extract)
utils::zip(zipfile = file.path(oldwd, "test_out_1.docx"), 
           files = list.files(path = ".", full.names = TRUE, all.files = FALSE, recursive = FALSE) )
setwd(oldwd)

zip_list("test_out_1.docx")
                       filename compressed_size uncompressed_size           timestamp permissions
1                        _rels/               0                 0 2019-03-26 17:09:16         700
2                   _rels/.rels             233               590 1979-12-31 23:00:00         600
3           [Content_Types].xml             340              1312 1979-12-31 23:00:00         600
4                     docProps/               0                 0 2019-03-26 17:09:16         700
5              docProps/app.xml             357               709 1979-12-31 23:00:00         600
6             docProps/core.xml             359               749 1979-12-31 23:00:00         600
7                         word/               0                 0 2019-03-26 17:09:16         700
8            word/fontTable.xml             445              1419 1979-12-31 23:00:00         600
9             word/document.xml             661              2562 1979-12-31 23:00:00         600
10            word/settings.xml             920              2604 1979-12-31 23:00:00         600
11         word/webSettings.xml             288               655 1979-12-31 23:00:00         600
12              word/styles.xml            2557             28902 1979-12-31 23:00:00         600
13                  word/theme/               0                 0 2019-03-26 17:09:16         700
14        word/theme/theme1.xml            1703              8394 1979-12-31 23:00:00         600
15                  word/_rels/               0                 0 2019-03-26 17:09:16         700
16 word/_rels/document.xml.rels             237               817 1979-12-31 23:00:00         600

The following code was producing a valid file:

oldwd <- getwd()
setwd(dir_extract)
files <- list.files(all.files = TRUE, recursive = TRUE)
zip::zip(zipfile = file.path(oldwd, "test_out_2.docx"), 
           files = files, recurse = TRUE )
setwd(oldwd)

zip_list("test_out_2.docx")
                       filename compressed_size uncompressed_size           timestamp permissions
1                        _rels/               0                 0 2019-03-26 17:09:16         700
2                   _rels/.rels             233               590 1979-12-31 23:00:00         600
3           [Content_Types].xml             340              1312 1979-12-31 23:00:00         600
4                     docProps/               0                 0 2019-03-26 17:09:16         700
5              docProps/app.xml             357               709 1979-12-31 23:00:00         600
6             docProps/core.xml             359               749 1979-12-31 23:00:00         600
7                         word/               0                 0 2019-03-26 17:09:16         700
8            word/fontTable.xml             445              1419 1979-12-31 23:00:00         600
9             word/document.xml             661              2562 1979-12-31 23:00:00         600
10            word/settings.xml             920              2604 1979-12-31 23:00:00         600
11         word/webSettings.xml             288               655 1979-12-31 23:00:00         600
12              word/styles.xml            2557             28902 1979-12-31 23:00:00         600
13                  word/theme/               0                 0 2019-03-26 17:09:16         700
14        word/theme/theme1.xml            1703              8394 1979-12-31 23:00:00         600
15                  word/_rels/               0                 0 2019-03-26 17:09:16         700
16 word/_rels/document.xml.rels             237               817 1979-12-31 23:00:00         600

test_out_0.docx
test_out_1.docx
test_out_2.docx

Do you have an idea of what is wrong with my zipr usage?

KR
David

Release 2.0.1

Prepare for release:

  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • rhub::check(platform = "solaris-x86-patched")
  • rhub::check(platform = "ubuntu-rchk")
  • revdepcheck::revdep_check(num_workers = 4)
  • Polish NEWS
  • If new failures, update email.yml then revdepcheck::revdep_email_maintainers()

Perform release:

  • Bump version (in DESCRIPTION and NEWS)
  • devtools::check_win_devel() (again!)
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Tag release
  • Bump dev version

Template from r-lib/usethis#338

zip_list fails with large files

I have a zip file containing a large file (> 4GB). The zip file was created using the zipr function (compression_level = 2, although I'm not sure that matters). When I call zip_list I get

Error in zip::zip_list("S:/SkeletonComparativeEffectStudy/cmOutput/CmData_l1_t1_c2_v2.zip") : 
  Cannot open zip file `S:\SkeletonComparativeEffectStudy\cmOutput\CmData_l1_t1_c2_v2.zip`

I can decompress the zip file just fine using unzip function. Other zip files that don't contain large files do work with zip_list.

This is a new development. The function was working a month ago. I'm currently on zip version 2.1.1, but it also happens on 2.1.0. My sessionInfo:

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.0.2 tools_4.0.2    zip_2.1.1 

Understanding permissions of unzipped files?

Hi @gaborcsardi & co,

I see that zip::unzip docs say:

If the zip archive stores permissions and was created on Unix, the permissions will be restored.

It appears this results in different behaviour than system unzip by default, which is tripping us up. Is there any way to override this to mimic the system behaviour?

Feature: allow manual specification of the ZIP directory structure

It would be fantastic to allow for manual specification of the ZIP directory structure in a zip::zipr or zip::zipr_append call, e.g.

zip::zipr("myzip.zip", files = list("myfile.txt" = "myfile-on-disk.txt"))

I skimmed the code and think it shouldn't be too hard by changing the key in get_zip_data() if names are present.
I can give it a try if you think that feature would be useful.

Ideally:

  • for plain files, the name directly translates to the key
  • for directories, the name replaces the key up to the specific directory (so the subdirectories and files have the same relative structure, just a different parent name / path)

Special Characters

Let say i have a file is called ""ô1.png" ("\u00f41.png"), when i try to zip it, i get an error.
zip::zipr("x.zip", files = "ô1.png")
Error in zip_internal(zipfile, files, recurse, compression_level, append = FALSE, :
zip error: Cannot add file ô1.pngto archivex.zip`` in file zip.c:394

Zip soft deprecation - zip docs need updating

Hi,

openxlsx has not (yet) been updated to take account of the soft deprecation of zip. In the process I thought I'd look up the changes in zip 2.0.1.

However, the documentation for ?zip::zip currently neither mentions the deprecation - and indeed advises to use zip rather than zipr:

Assuming the current working directory is foo, the following zip entries are created by zip:

zip("x.zip", c("bar/file1", "bar2", "../foo2"))
zip_list("x.zip")$filename
#> bar/file1
#> bar2
#> bar2/file2
#> ../foo2
#> ../foo2/file3
For zipr (and zipr_append), each specified file or directory in files is created as a top-level entry in the zip archive. We suggest that you use zip and zip_append for new code, as they don't create non-portable archives. For the same directory structure, these zip entries are created:

zipr("x.zip", c("bar/file1", "bar2", "../foo2"))
zip_list("x.zip")$filename
#> file1
#> bar2
#> bar2/file2
#> foo2
#> foo2/file3

potential doc error in zip/man/zip.Rd

Maybe I'm missing something but from my understanding in the following paragraph taken from zip/man/zip.Rd, it should read We suggest that you use \code{zipr} and \code{zipr_append} for new code[...]

For \code{zipr} (and \code{zipr_append}), each specified file or directory in
\code{files} is created as a top-level entry in the zip archive.
We suggest that you use \code{zip} and \code{zip_append} for new code, as they
don't create non-portable archives. For the same directory structure,
these zip entries are created:\preformatted{zipr("x.zip", c("bar/file1", "bar2", "../foo2"))

Fix building on rtools4.0

> install.packages("zip")
Installing package into ‘C:/Users/Jeroen/Documents/R/win-library/testing’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://cloud.r-project.org/src/contrib/zip_2.0.0.tar.gz'
Content type 'application/x-gzip' length 94959 bytes (92 KB)
downloaded 92 KB
 
* installing *source* package 'zip' ...
** package 'zip' successfully unpacked and MD5 sums checked
** libs
 
*** arch - i386
/mingw32/bin/gcc  -O2 -Wall  -std=gnu99 -mtune=generic miniz.c zip.c tools/cmdzip.c -o tools/cmdzip.exe
/mingw32/bin/gcc  -O2 -Wall  -std=gnu99 -mtune=generic miniz.c zip.c tools/cmdunzip.c -o tools/cmdunzip.exe
/mingw32/bin/gcc  -I"C:/PROGRA~1/R/R-testing/include" -DNDEBUG          -O2 -Wall  -std=gnu99 -mtune=generic -c init.c -o init.o
/mingw32/bin/gcc  -I"C:/PROGRA~1/R/R-testing/include" -DNDEBUG          -O2 -Wall  -std=gnu99 -mtune=generic -c miniz.c -o miniz.o
/mingw32/bin/gcc  -I"C:/PROGRA~1/R/R-testing/include" -DNDEBUG          -O2 -Wall  -std=gnu99 -mtune=generic -c rzip.c -o rzip.o
/mingw32/bin/gcc  -I"C:/PROGRA~1/R/R-testing/include" -DNDEBUG          -O2 -Wall  -std=gnu99 -mtune=generic -c zip.c -o zip.o
/mingw32/bin/gcc -shared -s -static-libgcc -o zip.dll tmp.def init.o miniz.o rzip.o zip.o -LC:/PROGRA~1/R/R-testing/bin/i386 -lR
installing via 'install.libs.R' to C:/Users/Jeroen/Documents/R/win-library/testing/zip
 
*** arch - x64
/mingw64/bin/gcc  -O2 -Wall  -std=gnu99 -mtune=generic miniz.c zip.c tools/cmdzip.c -o tools/cmdzip.exe
miniz.c:2942:9: error: conflicting types for 'freopen_s'
 errno_t freopen_s(FILE *restrict *restrict newstreamptr,
         ^~~~~~~~~
In file included from C:/rtools40/mingw64/x86_64-w64-mingw32/include/stdio.h:1007,
                 from miniz.h:499,
                 from miniz.c:27:
C:/rtools40/mingw64/x86_64-w64-mingw32/include/sec_api/stdio_s.h:100:27: note: previous declaration of 'freopen_s' was here
   _CRTIMP errno_t __cdecl freopen_s(FILE** _File, const char *_Filename, const char *_Mode, FILE *_Stream);
                           ^~~~~~~~~
make: *** [Makevars.win:9: tools/cmdzip.exe] Error 1
ERROR: compilation failed for package 'zip'
* removing 'C:/Users/Jeroen/Documents/R/win-library/testing/zip'
 
The downloaded source packages are in
        ‘C:\Users\Jeroen\AppData\Local\Temp\2\RtmpojBo8d\downloaded_packages’

Windows cannot complete the extraction. The Compressed (zipped) Folder '<file path>' is invalid

@gaborcsardi

I'm new to using this package, and so have a couple observations using this package when creating zip folders in R using a Windows platform.

  • After creating the zip file in R, the contents of the zip file cannot be viewed from Windows explorer.
  • When attempting to extract with the option of 'Extract all..." , the message 'Windows cannot complete the extraction. The Compressed (zipped) Folder '' is invalid' shows up.
  • Using the 'unzip' package also gives a response with similar outcome: 'In unzip(choose.files(), choose.dir()) : requested file not found in the zip file'
  • Using a winzip tool, however, the files are extracted along with all of the old junkpaths.

Is there anyway to avoid compressing the files with their junkpaths?

Absolute file paths in version 2.0.0

Seems like there might be an issue with absolute paths in the files argument of zip()? I'm getting the following error in version 2.0.0 but not 1.0.0:

zip::zip(zipfile = "foo.zip", files = here::here("foo.csv"))

Error in zip_internal(zipfile, files, recurse, compression_level, append = FALSE,  : 
  zip error: `Cannot add file `/Users/emmamendelsohn/project_folder/foo.csv` to archive `/Users/emmamendelsohn/project_folder/foo.zip`` in file `zip.c:394`

Changing the file path from absolute to relative works:

zip::zip(zipfile = "foo.zip", files =  "foo.csv")

The zipfile argument works regardless of path type.

Session Info
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.14.3

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] reprex_0.2.1 here_0.1     zip_2.0.0   

loaded via a namespace (and not attached):
[1] compiler_3.5.1  backports_1.1.3 rprojroot_1.3-2 tools_3.5.1     fs_1.2.6       
[6] Rcpp_1.0.0      rlang_0.3.1    

Windows: Crash of cmdunzip when executable on different drive than exdir

First of all, thank you a lot for this awesome package!

I just stumbled across a bug in Windows 10 that causes cmdunzip to crash. This crash occurs when the executable file cmdunzip is stored in a different drive (e.g. drive D:) than the exdir (e.g. drive C:).
Example command: D:\r_lib\zip\bin\x64\cmdunzip.exe C:/test/test.zip C:/test
I noticed that this only occurs if the path separator of the exdir is / instead of \..
This causes process_unzip to crash while unzip works just fine!

Zip without parent directory

I use zipr successfully but I get the structure:
Temporary/media....
I want the zip file to content what the temporary folder contents, without this unuseful Temporary/parent folder.

The rest is perfect, the stucture is kept and everything.

Any idea how to do that?

invalid zip file generated when compressing empty folder

@gaborcsardi
The files parameter in zip can be a folder according to examples, even the document didn't state so explicitly.

When this folder is an empty folder, the resulting zip is of size 22 bytes and not a valid zip file.

dir.create(tmp <- tempfile())
zipfile <- tempfile(fileext = ".zip")
# utils::zip(zipfile, tmp)
zip::zip(zipfile, tmp)
zip_list(zipfile)
# [1] filename          compressed_size   uncompressed_size
# <0 rows> (or 0-length row.names)
unzip(zipfile)
# Warning message:
#   In unzip(zipfile) : error 1 in extracting from zip file

Compare to the utils::zip behavior, which should be desired

dir.create(tmp <- tempfile())
zipfile <- tempfile(fileext = ".zip")
utils::zip(zipfile, tmp)
# adding: var/folders/f3/6cdx4zf94qz95r6d89s_4xcsrcsjqm/T//Rtmp1ZMU5C/file8a76deabf6b/ (stored 0%)
# zip::zip(zipfile, tmp)
zip_list(zipfile)
# filename compressed_size
# 1 var/folders/f3/6cdx4zf94qz95r6d89s_4xcsrcsjqm/T//Rtmp1ZMU5C/file8a76deabf6b/               0
# uncompressed_size
# 1                 0

Usually it doesn't make sense to compress an empty folder. However in my usage I'm saving a folder and restoring it later. The folder could be empty or with contents. With the behavior of utils::zip I don't need to do anything special. With current zip::zip behavior I need to avoid the zip creation when directory is empty, and avoid the restoring when zip is not generated.

If you decided a zip with empty folder should not be generated, at least it should raise some error and do not create the invalid zip file.

Suggestion: add remote connection for unzip()

In R, it is generally possible to read remote files directly. For example,

rmt1 <- file.path("https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5674813",
                  "bin/13024_2017_219_MOESM2_ESM.tsv")
read.delim( rmt1 )
#     Gene    Module
#  1 RPH3A turquoise
#  2  PLEC turquoise
#  3  DLG4 turquoise
#  4 SEPT5 turquoise
#  5 PLCB1 turquoise
#  6 ACTN2 turquoise
# ...

However, unzipping a remote file always requires that the file is first downloaded:

rmt2 <- file.path("https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5674813",
                  "bin/13024_2017_219_MOESM5_ESM.zip")
download.file( rmt2, "local.zip" )
zip::unzip( "local.zip", "Data 1.tsv" )

I think it could help with workflow streamlining, if it was possible to extract files directly, through a remote connection (similar to how read.delim() works):

zip::unzip( rmt2, "Data 1.tsv" )
# Error in zip::unzip(rmt2, "Data 1.tsv") :
#   zip error: `Cannot open zip file `https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5674813/bin/13024_2017_219_MOESM5_ESM.zip` for reading` in file `zip.c:238`
# In addition: Warning message:
# In normalizePath(zipfile) :
#   path[1]="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5674813/bin/13024_2017_219_MOESM5_ESM.zip": No such file or directory

Release 2.0.0

Prepare for release:

  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • rhub::check(platform = "solaris-x86-patched")
  • rhub::check(platform = "ubuntu-rchk")
  • revdepcheck::revdep_check(num_workers = 4)
  • Polish NEWS
  • If new failures, update email.yml then revdepcheck::revdep_email_maintainers()

Perform release:

  • Bump version (in DESCRIPTION and NEWS)
  • devtools::check_win_devel() (again!)
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Tag release
  • Bump dev version

Template from r-lib/usethis#338

zip with password

Hello,

I would like to compress a file with a password in R. Could this functionality be added to the zip or zipr function?

Thanks!

Release 2.0.4

Prepare for release:

  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • rhub::check(platform = "solaris-x86-patched")
  • rhub::check(platform = "ubuntu-rchk")
  • revdepcheck::revdep_check(num_workers = 4)
  • Polish NEWS
  • If new failures, update email.yml then revdepcheck::revdep_email_maintainers()

Perform release:

  • Bump version (in DESCRIPTION and NEWS)
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Tag release
  • Bump dev version

Template from r-lib/usethis#338

Error in file size when compressing large files

I have four files, each over 4GB. When I zip them into a single archive, the zip file is about 1GB, but the file sizes listed in the zip file is 25MB each. When extracting, the files are now 25MB, so apparently truncated the majority of data. Here's a screenshot.

untitled

> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] SelfControlledCaseSeries_1.3.0 DatabaseConnector_2.0.2        Cyclops_1.3.0                 

loaded via a namespace (and not attached):
 [1] ff_2.2-13           Rcpp_0.12.13        lattice_0.20-35     SqlRender_1.4.6     grid_3.4.0         
 [6] zip_1.0.0           RcppParallel_4.3.20 Matrix_1.2-9        fastmatch_1.1-0     ffbase_0.12.3      
[11] splines_3.4.0       tools_3.4.0         bit_1.1-12          survival_2.41-3     compiler_3.4.0     
[16] rJava_0.9-9   

Release 2.0.3

Prepare for release:

  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • rhub::check(platform = "solaris-x86-patched")
  • rhub::check(platform = "ubuntu-rchk")
  • revdepcheck::revdep_check(num_workers = 4)
  • Polish NEWS
  • If new failures, update email.yml then revdepcheck::revdep_email_maintainers()

Perform release:

  • Bump version (in DESCRIPTION and NEWS)
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Tag release
  • Bump dev version

Template from r-lib/usethis#338

adding a generic uncompress function

I'm using zip package in my app now because it doesn't rely on external programs.

I used to write a uncompress function that support zip, bz2, gz etc using R internal libraries only too. Since it's in same spirit, I'm wondering if you think it can be added to zip package.

The function was based on R.utils::decompressFile but with some important differences, especially that it will not delete input file by default. Originally it was designed to uncompress file, run some function on uncompressed files then delete the uncompressed file. It can also be changed to a function that simply uncompress the input.

If you like the idea I can create a pull request for this.

Error while trying to unzip a >6GB pre-compressed file

Hi,
I'm on Windows 10, using your package with R 3.5.1.

I'm facing an error while trying to extract a zip file where one of the files is a >6GB pre-compressed file.

unzip(file_zip, "F016MRL1_fact_data_09102019.csv")
Error in unzip(file_zip, "F016MRL1_fact_data_09102019.csv") : 
  zip error: `Cannot extract entry `F016MRL1_fact_data_09102019.csv` from archive `C:\Users\user_test\AppData\Local\Temp\RtmpUvqUUk\c079c0a571b5388fc12777cd\0.zip` in file `zip.c:305`

All the other files in the zip file can be extracted normally, only this huge one that cannot.

How can I extract this file, through R Script that works both on Windows and Linux?

Thank you for your time!

unzip return value

Hi Gabor,
I really like the zip package.

We'd like to use the unzip command and need the path to the unzipped file.

The utils::unzip function returns:
Otherwise for the "internal" method, a character vector of the filepaths extracted to, invisibly.

In the zip::unzip the return is invisible().

I'm not familiar with the calling of C code in the unzip function

.Call(c_R_zip_unzip, zipfile, files, overwrite, junkpaths, exdir)

and what it does return.

If it would be possible to implement a return as a character vector of the filepaths extracted to, it would be great.

Thanks, Christoph

How to add a file under a subfolder with zipr and keep the folder structure

zipr seem to be a improvement to zip, however I don't know how to achieve this:

  • Using the example in help, this folder structure
foo
  bar
      file1
      file1a
  bar2
      file2
foo2
  file3
  • sometimes I want to zip some files under a folder selectively, i.e. the folder foo but not all the files. With zip I just use relative path and add "bar/file1", "bar2".
  • With zipr the same usage will result file1 in top level and lost the bar subfolder structure.

How can I do this with zipr?

I think the problem here is that zip actually need two set of instructions:

  1. the input file list
  2. how to arrange input files in the zip

Usually it's assumed the result is same with input structure, so the behavior that zipr put bar/file1 at top level is a little bit strange to me, and I'm not sure if absolute path problem is relevant here as we are using relative paths.

2.2.1 cannot handle absolute path in Linux

cd ~/Desktop
touch text.txt
zip::zip("test.zip", "/home/xx/Desktop/text.txt")

zip error: Cannot add file /home/xx/Desktop/test.txtto archivetest.zip`` in file zip.c:348

unless I add mode = "cherry-pick". If this is expected, I would appreciate for better documentation to explain and better error than just "zip.c:348".

Release zip 2.1.1 to fix test failures on CRAN

Perform release:

  • Bump version (in DESCRIPTION and NEWS)
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Tag release
  • Bump dev version
Version: 2.1.0
Check: tests
Result: ERROR
     Running 'testthat.R' [3s/4s]
    Running the tests in 'tests/testthat.R' failed.
    Complete output:
     > library(testthat)
     > library(zip)
    
     Attaching package: 'zip'
    
     The following objects are masked from 'package:utils':
    
     unzip, zip
    
     >
     > test_check("zip")
     -- 1. Error: base path with non-ASCII characters (@test-paths.R#74) -----------
     zip error: `Cannot set permission on file `dir1/` in archive `zip1.zip`` in file `zip.c:356`
     Backtrace:
     1. zip::zip("zip1.zip", c("dir1", "dir2"), mode = "mirror")
     2. zip:::zip_internal(...)
    
     -- 2. Error: uncompressed path with non-ASCII characters (@test-paths.R#103) --
     zip error: `Cannot set permission on file `úáö<U+0151>é/` in archive `zip1.zip`` in file `zip.c:356`
     Backtrace:
     1. zip::zip("zip1.zip", root, mode = "mirror")
     2. zip:::zip_internal(...)
    
     == testthat results ===========================================================
     [ OK: 234 | SKIPPED: 3 | WARNINGS: 5 | FAILED: 2 ]
     1. Error: base path with non-ASCII characters (@test-paths.R#74)
     2. Error: uncompressed path with non-ASCII characters (@test-paths.R#103)
    
     Error: testthat unit tests failed
     Execution halted
Flavor: r-devel-linux-x86_64-debian-clang

Version: 2.1.0
Check: tests
Result: ERROR
     Running ‘testthat.R’ [2s/2s]
    Running the tests in ‘tests/testthat.R’ failed.
    Last 13 lines of output:
     2/2 mismatches
     x[1]: "úáöőé/"
     y[1]: "úáöőé/"
    
     x[2]: "úáöőé/ufileúá"
     y[2]: "úáöőé/ufileúá"
    
     ══ testthat results ═══════════════════════════════════════════════════════════
     [ OK: 240 | SKIPPED: 2 | WARNINGS: 0 | FAILED: 3 ]
     1. Failure: uncompressed path with non-ASCII characters (@test-paths.R#105)
     2. Failure: uncompressed path with non-ASCII characters (@test-paths.R#113)
     3. Failure: uncompressed path with non-ASCII characters (@test-paths.R#123)
    
     Error: testthat unit tests failed
     Execution halted
Flavor: r-release-macos-x86_64

Version: 2.1.0
Check: tests
Result: ERROR
     Running ‘testthat.R’ [3s/3s]
    Running the tests in ‘tests/testthat.R’ failed.
    Last 13 lines of output:
     2/2 mismatches
     x[1]: "úáöőé/"
     y[1]: "úáöőé/"
    
     x[2]: "úáöőé/ufileúá"
     y[2]: "úáöőé/ufileúá"
    
     ══ testthat results ═══════════════════════════════════════════════════════════
     [ OK: 240 | SKIPPED: 2 | WARNINGS: 0 | FAILED: 3 ]
     1. Failure: uncompressed path with non-ASCII characters (@test-paths.R#105)
     2. Failure: uncompressed path with non-ASCII characters (@test-paths.R#113)
     3. Failure: uncompressed path with non-ASCII characters (@test-paths.R#123)
    
     Error: testthat unit tests failed
     Execution halted
Flavor: r-oldrel-macos-x86_64

Release zip 2.1.0

Prepare for release:

  • devtools::check_win_devel() seems dead
  • rhub::check_for_cran()
  • rhub::check(platform = "solaris-x86-patched")
  • rhub::check(platform = "ubuntu-rchk")
  • revdepcheck::revdep_check(num_workers = 4)
  • Polish NEWS
  • If new failures, update email.yml then revdepcheck::revdep_email_maintainers()

Perform release:

  • Bump version (in DESCRIPTION and NEWS)
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Tag release
  • Bump dev version

Template from r-lib/usethis#338

Cannot download the package because of the executable file "cmdunzip.exe"

Our corporate policy prevents downloading any zip folder with executable file (i.e., cmdzip.exe). Any suggestion to get around this (of course not to ask my company to change the policy for me)?
I have also tried to install the source file "zip_2.0.4.tar" but got the following error message:
*** arch - i386
c:/Rtools/mingw_32/bin/gcc -O3 -Wall -std=gnu99 -mtune=generic miniz.c zip.c tools/cmdzip.c -o tools/cmdzip.exe
make: c:/Rtools/mingw_32/bin/gcc: Command not found
make: *** [Makevars.win:9: tools/cmdzip.exe] Error 127
ERROR: compilation failed for package 'zip'

It seemed to me that this also had something to do with the "cmdzip.exe" file.
Thanks!

zip folder appears empty after zipping

When trying to zip this Stata file I can successfully zip it as you can see in the reprex below

dir_path <- "C:\\Users\\cimentadaj\\Desktop\\Documents\\all_repos\\spain_shiny\\shiny\\test"
file_path <- paste0(dir_path, "\\ESS1e06_5.dta")
zip::zip(paste0(dir_path, "\\ess.zip"), file_path)
zip::zip_list(paste0(dir_path, "\\ess.zip"))
#>                                                                                        filename
#> 1 C:\\Users\\cimentadaj\\Desktop\\Documents\\all_repos\\spain_shiny\\shiny\\test\\ESS1e06_5.dta
#>   compressed_size uncompressed_size
#> 1        11279990         190919822

However, when I search inside the .zip file in Windows it appears as if it's empty:
ess_zip

If I unzip it with 7zip then I can see the files. However, zipping with utils::zip allows me both to see the files in the above picture and see them when unzipping with 7zip.

Maybe this is a Windows problem so here's my session info on a Windows 10.

devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.4.4 (2018-03-15)
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  tz       Europe/Paris                
#>  date     2018-07-30
#> Packages -----------------------------------------------------------------
#>  package   * version date       source                         
#>  backports   1.1.2   2017-12-13 CRAN (R 3.4.3)                 
#>  base      * 3.4.4   2018-03-15 local                          
#>  compiler    3.4.4   2018-03-15 local                          
#>  datasets  * 3.4.4   2018-03-15 local                          
#>  devtools    1.13.5  2018-02-18 CRAN (R 3.4.3)                 
#>  digest      0.6.15  2018-01-28 CRAN (R 3.4.3)                 
#>  evaluate    0.10.1  2017-06-24 CRAN (R 3.4.4)                 
#>  formatR     1.5     2017-04-25 CRAN (R 3.4.4)                 
#>  graphics  * 3.4.4   2018-03-15 local                          
#>  grDevices * 3.4.4   2018-03-15 local                          
#>  htmltools   0.3.6   2017-04-28 CRAN (R 3.4.4)                 
#>  knitr       1.20    2018-02-20 CRAN (R 3.4.4)                 
#>  magrittr    1.5     2014-11-22 CRAN (R 3.4.4)                 
#>  memoise     1.1.0   2018-03-20 Github (hadley/memoise@06d16ec)
#>  methods   * 3.4.4   2018-03-15 local                          
#>  Rcpp        0.12.17 2018-05-18 CRAN (R 3.4.4)                 
#>  rmarkdown   1.9     2018-03-01 CRAN (R 3.4.4)                 
#>  rprojroot   1.3-2   2018-01-03 CRAN (R 3.4.4)                 
#>  stats     * 3.4.4   2018-03-15 local                          
#>  stringi     1.1.7   2018-03-12 CRAN (R 3.4.4)                 
#>  stringr     1.3.1   2018-05-10 CRAN (R 3.4.4)                 
#>  tools       3.4.4   2018-03-15 local                          
#>  utils     * 3.4.4   2018-03-15 local                          
#>  withr       2.1.2   2018-06-26 Github (r-lib/withr@fe56f20)   
#>  yaml        2.1.18  2018-03-08 CRAN (R 3.4.4)                 
#>  zip         1.0.0   2017-04-25 CRAN (R 3.4.4)

Release 2.0.2

Prepare for release:

  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • rhub::check(platform = "solaris-x86-patched")
  • rhub::check(platform = "ubuntu-rchk")
  • revdepcheck::revdep_check(num_workers = 4)
  • Polish NEWS
  • If new failures, update email.yml then revdepcheck::revdep_email_maintainers()

Perform release:

  • Bump version (in DESCRIPTION and NEWS)
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Tag release
  • Bump dev version

Template from r-lib/usethis#338

Can't install zip on r-studio

My distribution is:
Distributor ID: Debian
Description: Debian GNU/Linux 9.3 (stretch)
Release: 9.3
Codename: stretch

I tried to install zip with install.packages('zip', dependencies = TRUE), but it returns:

Installing package into ‘/home/yusuzech/lib’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/zip_1.0.0.tar.gz'
Content type 'application/x-gzip' length 60823 bytes (59 KB)
==================================================
downloaded 59 KB

[1] "lib path set to /home/yusuzech/lib"
$`lib path set to /home/yusuzech/lib`
NULL

* installing *source* package ‘zip’ ...
** package ‘zip’ successfully unpacked and MD5 sums checked
** libs
gcc -I/usr/local/lib/R/include -DNDEBUG   -I/usr/local/include   -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c init.c -o init.o
gcc -I/usr/local/lib/R/include -DNDEBUG   -I/usr/local/include   -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c rzip.c -o rzip.o
gcc -I/usr/local/lib/R/include -DNDEBUG   -I/usr/local/include   -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c zip.c -o zip.o
gcc -shared -L/usr/local/lib/R/lib -L/usr/local/lib -o zip.so init.o rzip.o zip.o -L/usr/local/lib/R/lib -lR
installing to /home/yusuzech/lib/zip/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
[1] "lib path set to /home/yusuzech/lib"
$`lib path set to /home/yusuzech/lib`
NULL

Error: package or namespace load failed for ‘zip’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/yusuzech/lib/zip/libs/zip.so':
  /home/yusuzech/lib/zip/libs/zip.so: failed to map segment from shared object
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/yusuzech/lib/zip’
Warning in install.packages :
  installation of package ‘zip’ had non-zero exit status

The downloaded source packages are in
	‘/tmp/Rtmp9xpHQU/downloaded_packages’

I have no idea what is wrong.

withCallingHandlers does not suppress custom message

I want to use zip in gert to archive exactly the files tracked by git (so no auto-recurse). I don't think this can be done with zipr so we use the soft-deprecated zip function:

zip::zip("archive.zip", gert::git_ls()$path)

The documentation recommends to do this:

withCallingHandlers(
  zip::zip(...),
  deprecated = function(e) NULL)

But that doesn't actually suppress the message (in R 4.0)

test_zip <- function(){
  file.copy(R.home('COPYING'), 'COPYING')
  zip::zip('test.zip', 'COPYING', recurse = FALSE)
}

withCallingHandlers(test_zip(), deprecated = function(e) NULL)
## Note: zip::zip() is deprecated, please use zip::zipr() instead

This does work though: suppressMessages(test_zip())

openxlsx::saveWorkbook(): zip error

Hi folks,

got trouble with the openxlsx-package after several package updates.
The issue was already posted in the related github repository. However, no helping answers so far.
As far as I know, openxlsx relies on the zip() function of r-lib and the error code seems to be related only to the call of the zip-package.
Here is the issue in opxlsx-repository

Describe the bug
When trying to save a workbook variable to an .xlsx file I receive the following error message:

Fehler in zip_internal(zipfile, files, recurse, compression_level, append = FALSE, :
zip error: Cannot add file [Content_Types].xmlto archivefile347c2455470.xlsx`` in file zip.c:394

This is an example oc code that leads to the error

# RScript for 'openxls saveWorkbook'-Issue:
library(openxlsx)
# Load dataset 'mtcars'
var1 <- mtcars
# Create workbook variable
wb1 <- createWorkbook("wb_mtcars")
addWorksheet(wb = wb1, sheetName = names(var1)[1])
writeData(wb=wb1, sheet = names(var1)[1], x = var1[1] ,withFilter = FALSE)
saveWorkbook(wb=wb1, file=paste(getwd(), '/wb1.xlsx',sep = ""),overwrite = TRUE)

System environmental variables seem to be ok and writing on the AppDat/Local directory seems to be ok as well.
Any idea, where I could continue to find a reason for this error?`

Please let me know if any additional information is required.

Just for information purposes, here is another (maybe) similar case.

File Timestamps are not preserved

Dear all,
I need to preserve the timestamps of the files to zip (creation date).
The zip process used in this library applies the compression date to all file within the zip.
I did not find any package implementing this behaviro, while common zipping GUI (winrar/zip) do preserve the creation date.
Could this become a future feature in this package, or would you suggest other options?

Many Thanks for this useful package.

zip and zipr fail to use non-ASCII paths

Both zipr and zip fail to use non-ASCII paths, at least on Windows. I open this issue as a more general bug than #46 (which refers to the consequence with openxlsx) but it's basically the same bug.

Here is a code for reproducing this issue:

library(zip)

# --- Create 1 test directory and 2 sub-directories with accent, with 1 file inside the second one ----
dir.create("C:/Test/")
dir.create("C:/Test/compressed_é")
dir.create(dir_with_accent <- "C:/Test/uncompressed_é")
cat("this is one file", file = file.path(dir_with_accent, "file1.txt"))

# --- Create an empty zip file with accents in its name and path ----
# The empty zip file is made with the following 22 bytes : PK\x05\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
empty_zip_data <- as.raw(c(0x50, 0x4B, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00))
zipfile_with_accent <- "C:/Test/compressed_é/compressé.zip"
writeBin(empty_zip_data, zipfile_with_accent)

# --- Using zip & zipr with zipfile_with_accent & dir_with_accent (fails for both zip and zipr) ----
zipr(zipfile_with_accent, dir_with_accent)
zip(zipfile_with_accent, dir_with_accent)

The execution gives the following errors:

> zipr(zipfile_with_accent, dir_with_accent)
Error in zip_internal(zipfile, files, recurse, compression_level, append = FALSE,  : 
  zip error: `Cannot add file `uncompressed_é/file1.txt` to archive `C:/Test/compressed_é/compressé.zip`` in file `zip.c:394`
> zip(zipfile_with_accent, dir_with_accent)
Error in zip_internal(zipfile, files, recurse, compression_level, append = FALSE,  : 
  zip error: `Cannot add directory `C:/Test/uncompressed_é/` to archive `C:/Test/compressed_é/compressé.zip`` in file `zip.c:387`

But if you remove the accents in the names and path, then there is no error, at least with zipr.
With zip, I still get this error even when there are no accents, but I suppose this is because there is a non-ASCII character in my Windows username (which is "François").

Handle long file names on Windows

i Packaging devtools 2.3.1.9000                                            
x Failed to uncompress devtools 2.3.1.9000 258ms                           
(############ ) | [BLD]  76/77 | 1 | [INS]  76/77     | building devtools
Error: Failed to uncompress 'devtools' from 'C:\\Users\\csard\\AppData\\Local\\Temp\\Rtmp8gyfqS\\filee5685c3a14d3/src/contrib/devtools_2.3.1.9000_df619ce29b722f34e5d5f83e336881f12ab3ed05.tar.gz-tree'.

Standard output:
O> 

Standard error:
E> zip error: `Cannot extract file `r-lib-devtools-df619ce/tests/testthat/shallowRepo/objects/pack/pack-c4e0f1d1d68408f260cbbf0a533ad5f6bfd5524e.idx`` in file `zip.c:211`

See `.Last.error.trace` for a stack trace.
                                                                         
> .Last.error.trace

 Stack trace:

 1. pp$install()
 2. pkgdepends:::install_package_plan(plan, lib = private$library,  ...
 3. base:::withCallingHandlers({ ...
 4. pkgdepends:::handle_events(state, events)
 5. pkgdepends:::handle_event(state, i)
 6. pkgdepends:::stop_task(state, worker)
 7. pkgdepends:::stop_task_package(state, worker)
 8. pkgdepends:::stop_task_package_uncompress(state, worker)
 9. base:::throw(new_pkg_uncompress_error("Failed to uncompress {pkg} from {state$plan$file[[pk ...

 x Failed to uncompress 'devtools' from 'C:\\Users\\csard\\AppData\\Local\\Temp\\Rtmp8gyfqS\\filee5685c3a14d3/src/contrib/devtools_2.3.1.9000_df619ce29b722f34e5d5f83e336881f12ab3ed05.tar.gz-tree'. 

Possibly something in the zip package?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.