[REBOL] Re: Zips
From: al:bri:xtra at: 9-Jan-2003 12:47
Carl Read wrote:
> Sure, sometimes we need to pack script and data together, but isn't their
(wasn't there?) a REBOL way to do this? .rip or some such?
> Simple things should be simple...
Rebol [
Name: 'Pack
Title: "Pack"
File: %Pack.r
Author: "Andrew Martin"
eMail: [Al--Bri--xtra--co--nz]
Web: http://valley.150m.com
Date: 9/January/2003
Version: 1.1.3
Purpose: {Self-extracting file packer & unpacker.}
Category: [util compress 5]
Needs: [%"Recursive Read.r"]
]
make object! [
Unpacker: [
Rebol [
Name: 'Unpacker
Title: "Self-extracting file unpacker."
Date: (now)
]
Unpack: func [Pack [block!]][
parse Pack [
some [
set File file! set Data binary! (
make paren! [
write/binary File decompress Data
]
)
| set File file! (
make paren! [make-dir/deep File]
)
]
end
]
]
Unpack ; 'Case goes here.
]
set 'Pack function [
{Self-extracting File packer.}
File [file! block!] "File can be directory or block of file!
values."
/Deep "Copy subdirectories as well."
] [
Files Block Directory
] [
append/only compose/deep Unpacker any [
if block? File [
Block: File
map Block func [File [file!]] [
either #"/" = last File [
File
] [
reduce [File compress read/binary File]
]
]
]
if #"/" = last File [
Directory: File
map either Deep [
recursive-read Directory
] [
read Directory
] func [File [file!]] [
either #"/" = last File [
File
] [
reduce [File compress read/binary Directory/:File]
]
]
]
reduce [File compress read/binary File]
]
]
]
Use:
save %Packed.r pack %MyFilesDirectory/
Andrew Martin
ICQ: 26227169 http://valley.150m.com/