When handler is not specified, the entries of the LHA file are printed.
> readLha("pnuts.lha")
0 Fri May 05 18:30:30 JST 2000 pnuts/
0 Fri May 05 18:30:30 JST 2000 pnuts/awt/
2869 Tue May 30 16:08:32 JST 2000 pnuts/awt/DialogOutputStream.class
4980 Fri May 05 18:30:30 JST 2000 pnuts/awt/Layout.class
....
When handler is specified, the function is called with a object that has the following properties.
Property Name Type input InputStream header.path String header.lastModified java.util.Date header.originalSize long header.compressedSize long
For instance, the following function writes the content of a file in a LHA file to the specified OutputStream.
function extract(lhafile, name, out){
readLha(lhafile, function (e) if (e.header.path == name) read(e.input, out))
}
readLhaEntries() returns a generater which generates references to the archived files.
Property Name Type input InputStream header LhaHeader header.path String header.lastModified java.util.Date header.origialSize long header.compressedSize long
for (e : readLhaEntries(zfile)){
println(e.header.path)
}
extractLha() extracts the specified entries of a LHA file in a number of ways.
First parameter specifies the LHA file to be read.
If the 2nd argument is a directory, the entries of the LHA file are stored in the directory. If the 2nd argument is a file, the LHA entries are stored in the file.
extractLha("foo.lha", ".")
If entryName is specified as the third parameter, LHA headers that matches the entryName are extracted. If matchFunction is specified, LHA entries that the function returns true are extracted.
If only two parameters are specified, all entries of the LHA file are extracted.
extractLha("rt.lha", "script.lha", function (n) n.startsWith("javax/script/"))
If either output or writer is specified, a LHA entry is written to the stream.
extractLha("foo.lha", getContext().getWriter(), "pnuts/lang/pnuts.properties")
writeLha() creates a LHA file from the all files in fileList, and saves them in the file or writes to the specified outputStream.
writeLha("foo.lha", ["foo.txt", "bar.class"])
writeLha("classes.lha", "classes")
writeLhaEntries() creates a LHA file, specifying a Generater that generates references to the archived files. The file references should have the following properties.
Property Name Type input InputStream (any objects that open() can handle), null if no data is present header.path String header.lastModified java.util.Data
function fileEntries(dir){
for (i : dir.files()){
f = File(i)
yield {"header"=>{"path"=>f.name, "lastModified"=>date(f.lastModified())},
"input"=>isDirectory(f) ? null : f}
}
}
writeLhaEntries(filename, fileEntries("src"))