| setZipLevel |
(Stream stream, int level) |
yoix.io |
| |
Sets the compression level of a zipped, output
stream
to
level,
which is in the range 0 to 9, inclusive.
A
levelvalueoutsideoftheacceptablerangeisequivalentto
requesting the default compression used by Java.
The
stream
must be a
zipped stream opened for writing.
The write buffers are always flushed before the zip level is set.
The constants,
DEFAULT_COMPRESSION,
NO_COMPRESSION,
BEST_SPEED
and
BEST_COMPRESSION
are available to use as values for
level.
| |
| Example: |
The following example opens a new zip file, writes a pointless comment
using
setZipComment,
uses
setZipLevel
to request maximum compression and writes out some text to the file.
Then the compression level for the next entry is set to
NO_COMPRESSION
and some more text is written out.
The file is then closed and the zip entry headers are retrieved and
written to standard output.
The last step is to remove the test file.
import yoix.io.*;
import yoix.stdio.*;
import yoix.system.*;
import yoix.util.*;
File f = {
String name = tmpnam(null);
int mode = WRITE;
int filters = ZIPPED;
int open = true;
};
setZipComment(f, "This is an inaccessible comment.");
setZipLevel(f, BEST_COMPRESSION);
ZipEntry ze;
ze.name = "first_sentence";
ze.extra = "The Iliad (translated by Robert Fagles)";
f.nextentry = ze;
f.nextbuf = "\
Rage - Goddess, sing the rage of Peleus' son Achilles,\n\
murderous, doomed, that cost the Achaeans countless loses,\n\
hurling down to the House of Death so many sturdy souls,\n\
great fighters' souls, but made their bodies carrion,\n\
feasts for the dogs and birds,\n\
and the will of Zeus was moving toward its end.\n";
setZipLevel(f, NO_COMPRESSION);
ze.name = "second_sentence";
f.nextentry = ze;
f.nextbuf = "\
Begin, Muse, when the two first broke and clashed,\n\
Agamemnon, lord of men and brilliant Achilles.\n\n";
close(f);
Dictionary ents = getZipEntries(f.fullname);
int i;
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));
}
unlink(f.fullname);
The output would look something like the following:
name=second_sentence
comment=
compressedsize=104
crc=2311093564
deflated=1
extra=The Iliad (translated by Robert Fagles)
size=99
timestamp=Sun Oct 15 22:20:28 EDT 2000
name=first_sentence
comment=
compressedsize=205
crc=4083406486
deflated=1
extra=The Iliad (translated by Robert Fagles)
size=305
timestamp=Sun Oct 15 22:20:28 EDT 2000
Note that by setting
NO_COMPRESSION
for the second entry, the compressed size is actually 5 bytes greater than
the uncompressed size due to some required information that is part of
any deflated entry.
| | |
| Return: |
none
| | |
| See Also: |
getZipEntries,
getZipMember,
setZipComment
|
|
Yoix is a registered trademark of AT&T Inc.
|