5 zip File Extraction
(require file/unzip) | package: base |
procedure
(unzip in [ entry-reader #:preserve-timestamps? preserve-timestamps? #:utc-timestamps? utc-timestamps?]) → void? in : (or/c path-string? input-port?)
entry-reader :
(if preserve-timestamps? (bytes? boolean? input-port? (or/c #f exact-integer?) . -> . any) (bytes? boolean? input-port? . -> . any)) = (make-filesystem-entry-reader) preserve-timestamps? : any/c = #f utc-timestamps? : any/c = #f
For each entry in the archive, the entry-reader procedure is called with three or four arguments: the byte string representing the entry name, a boolean flag indicating whether the entry represents a directory, an input port containing the inflated contents of the entry, and (if preserve-timestamps?) #f or a timestamp for a file. The default entry-reader unpacks entries to the filesystem; call make-filesystem-entry-reader to configure aspects of the unpacking, such as the destination directory.
Normally, zip archives record modification dates in local time, but if utc-timestamps? is true, then the time in the archive is interpreted as UTC.
Changed in version 6.0.0.3 of package base: Added the #:preserve-timestamps? argument. Changed in version 6.0.1.12: Added the #:utc-timestamps? argument.
procedure
(call-with-unzip in proc) → any
in : (or/c path-string? input-port?) proc : (-> path-string? any)
Added in version 6.0.1.6 of package base.
procedure
(make-filesystem-entry-reader [ #:dest dest-path #:strip-count strip-count #:exists exists])
→
((bytes? boolean? input-port?) ((or/c #f exact-integer?)) . ->* . any) dest-path : (or/c path-string? #f) = #f strip-count : exact-nonnegative-integer? = 0
exists :
(or/c 'skip 'error 'replace 'truncate 'truncate/replace 'append 'update 'can-update 'must-truncate) = 'error
If dest-path is not #f, every path in the archive is prefixed to determine the destination path of the extracted entry.
If strip-count is positive, then strip-count path elements are removed from the entry path from the archive (before prefixing the path with dest-path); if the item’s path contains strip-count elements, then it is not extracted.
If exists is 'skip and the file for an entry already exists, then the entry is skipped. Otherwise, exists is passed on to open-output-file for writing the entry’s inflated content.
Changed in version 6.0.0.3 of package base: Added support for the optional timestamp argument in the result function.
procedure
(read-zip-directory in) → zip-directory?
in : (or/c path-string? input-port?)
This procedure performs limited I/O: it reads the list of entries from the zip file, but it does not inflate any of their contents.
procedure
(zip-directory? v) → boolean?
v : any/c
procedure
(zip-directory-entries zipdir) → (listof bytes?)
zipdir : zip-directory?
procedure
(zip-directory-contains? zipdir name) → boolean?
zipdir : zip-directory? name : (or/c bytes? path-string?)
Directory entries match with or without trailing slashes.
procedure
(zip-directory-includes-directory? zipdir name) → boolean? zipdir : zip-directory? name : (or/c bytes? path-string?)
procedure
(unzip-entry in zipdir entry [ entry-reader #:preserve-timestamps? preserve-timestamps? #:utc-timestamps? utc-timestamps?]) → void? in : (or/c path-string? input-port?) zipdir : zip-directory? entry : (or/c bytes? path-string?)
entry-reader :
(if preserve-timestamps? (bytes? boolean? input-port? (or/c #f exact-integer?) . -> . any) (bytes? boolean? input-port? . -> . any)) = (make-filesystem-entry-reader) preserve-timestamps? : any/c = #f utc-timestamps? : any/c = #f
The entry parameter is a byte string whose name must be found in the zip file’s central directory. If entry is not a byte string, it is converted using path->zip-path.
The read-entry argument is used to read the contents of the zip entry in the same way as for unzip.
If entry is not in zipdir, an exn:fail:unzip:no-such-entry exception is raised.
Changed in version 6.0.0.3 of package base: Added the #:preserve-timestamps? argument. Changed in version 6.0.1.12: Added the #:utc-timestamps? argument.
procedure
(call-with-unzip-entry [in] entry proc) → any
in : path-string? = input-port entry : path-string? proc : (-> path-string? any)
Added in version 6.0.1.6 of package base.
procedure
(path->zip-path path) → bytes?
path : path-string?
struct
(struct exn:fail:unzip:no-such-entry exn:fail (entry) #:extra-constructor-name make-exn:fail:unzip:no-such-entry) entry : bytes?