| getZipEntries |
(String path) |
yoix.io |
| |
Reads the zipped file specified by
path
and returns a dictionary of
ZipEntry
objects indexed by name.
The
path
should specify a zipped file that can be accessed directly (i.e., not
over a network using a URL connection).
If the supplied file is inappropriate,
a
NULL
dictionary is returned.
If there were no zip entries in the file, a zero length dictionary is
returned.
| |
| Example: |
The following script opens a jar or zip file and displays each of
its
ZipEntry
elements and then uses the name of the entry in the first
dictionary position to retrieve the data portion of that entry.
Refer to the
getZipMember
documentation for additional information.
import yoix.io.*;
import yoix.stdio.*;
import yoix.util.*;
int i;
String zipfile = argc > 1 ? argv[1] : "test.jar";
Dictionary ents = getZipEntries(zipfile);
if(!ents) {
fprintf(stderr,
"The path (%s) does not indicate a valid zip file.\n",
zipfile);
exit(1);
}
for(i=0; i<ents@length; i++) {
fprintf(stdout, "name=%s\n", ents[i].name);
fprintf(stdout, "\tcomment=%s\n", ents[i].comment);
fprintf(stdout, "\tcompressedsize=%d\n", ents[i].compressedsize);
fprintf(stdout, "\tcrc=%d\n", ents[i].crc);
fprintf(stdout, "\tdeflated=%d\n", ents[i].deflated);
fprintf(stdout, "\textra=%s\n", ents[i].extra);
fprintf(stdout, "\tsize=%d\n", ents[i].size);
fprintf(stdout, "\ttimestamp=%s\n", date(ents[i].timestamp));
}
Stream s = getZipMember(zipfile, ents[0].name);
fprintf(stdout, "\nRetrieving: %s\n\n", ents[0].name);
while(line = s.nextline)
stdout.nextline = line;
close(s);
The result on standard output might look like the following:
name=odyssey.txt
comment=
compressedsize=108
crc=2427229966
deflated=1
extra=The Odyssey (translation: Robert Fagles)
size=143
timestamp=Thu Oct 5 22:46:02 EDT 2000
name=aeneid.txt
comment=
compressedsize=116
crc=1464211969
deflated=1
extra=The Aeneid (translation: Allen Mandelbaum)
size=154
timestamp=Thu Oct 5 22:46:02 EDT 2000
Retrieving: odyssey.txt
Sing to me of the man, Muse, the man of twists and turns
driven time and again off course, once he had plundered
the hallowed heights of Troy.
Note that because these
ZipEntry
components were retrieved from the central directory of the
zipped file rather than the sequential LOC headers,
they have many more elements in their catalog
populated with meaningful information.
Refer to the
ZipEntry
documentation for more information about this point.
| | |
| Return: |
Dictionary
| | |
| See Also: |
close,
getZipMember,
ZipEntry
|
|
Yoix is a registered trademark of AT&T Inc.
|