In contemplating what I'm looking to achieve with R3C, I've been backtracking on ways in which I've/we've approached working with common formats.
I've mused over Zip before and given thought I'd revisit this first. This time in Rebol 2 (along with a core-friendly Deflate implementation).
Unpacking
First goal here is versatility: no unzip and be done—rather try to isolate the atomic steps of retrieval so as to offer more control over the process. Thus:
archive: zip/load %archive.zip
Returns an object representing the archive and
entry: zip/step archive
Will return the next entry (or none if at the end). So far nothing has been decompressed thus is a relatively cheap operation. Metadata for that entry such as filename/date is readily available.
entry/filename
entry/date
As is the compressed content itself:
content: zip/unpack entry
With these building blocks, it's easy enough to extract a whole archive or target specific files:
doc: zip/load %document.odt
while [
file: zip/step doc
][
if file/filename == %mimetype [
probe zip/unpack file
; => "application/vnd.oasis.opendocument.text"
]
]
Packing
This presented a few conceptional challenges as to how one represents archives/entries in construction. Essentially an archive is a block of entry objects sharing the same structure as above (conceptually you could just throw those extracted entry objects into a block and pack them, but in writing this I don't recall if I implemented that—need to go back and look, would be cool if so).
new-archive: reduce [
zip/prepare %thing #{01234567}
]
write %thing.zip zip/pack new-archive
Again, a key here is to keep the steps atomized so they can be handled in different ways. One such way is a wrapper that provides shorthand contextual functions (in one sense a 'dialect' but is just regular code).
write %thing.zip zip/build [
add-file %mimetype "application/x-rebol+zip"
repeat count 3 [
add-file join %thing- count #{01234567}
]
add-comment "A possibly useful note"
]
Relevance
I don't think anything here resembles anything particularly revolutionary, only that it's a departure from the typical Rebol way of doing things that I think opens up some possibilities. This isn't an end point, there's a bit more digging to do