Osy#betaRun it on Osyrin: osyrin.com

Reference / Stdlib

Zip.List — what an archive holds

List<string> Zip.List(byte[] archive)

`Zip.List(bytes)` answers the names a ZIP archive holds, in archive order — read from its central directory only, so nothing is decompressed and an archive built to expand to gigabytes costs exactly its own size. Bytes that are not a readable ZIP answer an empty list.

preview1 example compiled by CIstdlibfiles

Summary#

A customer attaches logs.zip; the desk wants to see what is in it before saving it anywhere:

foreach (var name in Zip.List(File.ReadAllBytes(attached.File))) { … }   // "logs/", "logs/app.log", "config.json"

Signature#

List<string> Zip.List(byte[] archive)   // entry names in archive order; a folder's own entry ends in "/"

Description#

Only the directory is read. The listing comes from the archive's central directory; no entry is opened, so the call is as cheap and as safe for a hostile archive as for an honest one. It answers at most 1000 names.

Not an archive is an answer, not a fault. Bytes that are not a readable ZIP — a renamed file, a truncated download — answer an empty list, which a page shows as "this archive could not be read" rather than as an error in the code that asked.

It runs on the server: the bytes are a byte[], which a page has no representation of, so a page is sent the listing.

Examples#

List<string> Folders(byte[] archive) {
  return Zip.List(archive).Where(n => n.EndsWith("/")).ToList();
}

int FileCount(byte[] archive) {
  return Zip.List(archive).Count(n => !n.EndsWith("/"));
}

See also#

Related

Mail on the wire — Mime.Parse, Mime.Build, Imap.Fetch, Smtp.Send

The four calls a mail kit is built from. `Mime.Parse` reads a whole RFC 5322 message — headers, text and HTML bodies…

Encoding — Base64, hex, text encodings, URL, HTML

Encode and decode text — Base64, URL percent-encoding, and HTML escaping — with the C#-faithful spellings…

[Attachment] — a file readable wherever its row is

`[Attachment]` on a `FileAsset` reference makes the file readable by exactly the people who may read the row holding it…

The Conversations kit — one timeline per conversation, across every channel

`Osysharp.Conversations` keeps a conversation with a customer as ONE ordered timeline — their messages, the team's…