CX · Reference guidezip
PlaygroundDownloadsAboutv0.18.0-pre.1

zip

Zip archive codec over the CX bytes scalar kind. pack turns a sequence of entry maps (name, data, optional mtime-unix, method and unix mode) into deterministic, byte-stable archive bytes; unpack decodes every entry with CRC-32 verification; entries lists central-directory metadata without decompressing payloads; extract decodes one entry by name; comment reads the archive-level comment. Pure archive manipulation with no I/O — file and stream I/O composes via cx-stdlib/io. zip64 archives are read natively; encryption and compression methods other than store/deflate are refused loudly with typed errors (CXER5200-5205).

zip:pack

[$zip:pack] -> bytes — Pack a sequence of entry maps into deterministic zip archive bytes; refuses unsafe or duplicate names.

      [?lib 'cx-stdlib/zip']
[?lib 'cx-stdlib/bytes']
[$bytes:length [$zip:pack ()]]
    
      22
    

zip:unpack

[$zip:unpack] -> [sequence map] — Decode every archive entry to a map of name, data, mtime-unix (and mode when carried), verifying each payload's CRC-32.

      [?lib 'cx-stdlib/zip']
[$count [$zip:unpack [$zip:pack ({name: 'a.txt', data: 'alpha'})]]]
    
      1
    

zip:entries

[$zip:entries] -> [sequence map] — List central-directory metadata (name, size, compressed-size, method, crc32, comment) without decompressing payloads.

      [?lib 'cx-stdlib/zip']
[?let [= $a [$zip:pack ({name: 'a.txt', data: 'hello'})]]
      [= $e [$nth [$zip:entries $a] 1]]
  ($e/name, $e/size)]
    
      ('a.txt', 5)
    

zip:extract

[$zip:extract] -> bytes — Decode a single entry's payload by name, CRC-verified; raises CXER5202 when the name is absent.

      [?lib 'cx-stdlib/zip']
[?lib 'cx-stdlib/bytes']
[$bytes:to-string-utf8 [$zip:extract [$zip:pack ({name: 'a.txt', data: 'alpha'})] "a.txt"]]
    
      alpha
    

zip:comment

[$zip:comment] -> string — Read the archive-level end-of-central-directory comment; '' when the archive carries none.

      [?lib 'cx-stdlib/zip']
[$zip:comment [$zip:pack ({name: 'a.txt', data: 'alpha'})]]
    
      ''