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#
- The Conversations kit — one timeline per conversation, across every channel — a ZIP attached to a message is listed on the timeline with this
- [Attachment] — a file readable wherever its row is — reading an attached file's bytes
- Mail on the wire — Mime.Parse, Mime.Build, Imap.Fetch, Smtp.Send — the mail an archive usually arrives in