You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Apache Wiki <wi...@apache.org> on 2009/03/14 23:30:52 UTC
[Commons Wiki] Update of "Compress" by ChristianGrobmeier
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Commons Wiki" for change notification.
The following page has been changed by ChristianGrobmeier:
http://wiki.apache.org/commons/Compress
The comment on the change is:
modified everything to fit to new implementation, creating link to todo list
------------------------------------------------------------------------------
##language:en
= Component Overview =
- Compress is an API for working with tar, zip and bzip2 files.
+ Compress is an API for working with the following files: tar, zip, bzip2, cpio, ar, gz, jar.
= Quick Start =
- *compress* is divided between Compressors and Archivers. While you have
- to get an Archiver from a factory when just archiving one or more files
- to the target file (tar), you'll need a Compressor for reducing the files size (bzip2).
+ *compress* is a stream based API. It's original code in this component came from Avalon's Excalibur, but originally from Ant, as far as life in Apache goes. It has migrated via:
+ Ant -> Avalon-Excalibur -> Commons-IO -> Commons-Compress.
+ More credits can be found in NOTICE.txt file.
+
+ *compress* divides the implementation in Compressors and Archivers. For each one an factory is implemented.
+ Basically you have to get the stream implementation from the factory, create an entry, put this into the stream and stream.
+
+ Some experimental code makes it possible to modify archiver and compressor files. This means you can delete from for example a zip file.
Please note:
- There are discussion of "sponsoring" compress with code from TrueZip (https://truezip.dev.java.net/)
- and of enhancing compress design. At the moment the current implementation
- is considered as complex by some people. An deeper look at compress implementation
- can be found on the CompressImplementationDetails page.
+ There were discussion of "sponsoring" compress with code from TrueZip (https://truezip.dev.java.net/). The result was, not to include any code from this project (see mailinglists).
+ There was a discussion about the complex file based implementation too. The result was to start again with a stream based implementation and move the old one to a branch. More information about the old implementation can be found on the CompressImplementationDetails page.
+
+ = Roadmap =
+ Compress looks like moving to proper now and prepares for the first release. If you want to help, here is the CompressRoadmap.
== Archiver ==
- To pack an archive, you have to get an archiver via the ArchiverFactory. At the moment it's possible to get a "zip" or a "tar" archiver. Add your files to the archiver and call save to store the archive.
+ To pack an archive, you have to get an archiver stream via the ArchiverFactory. Add your streams to the archiver and stream.
+ Archiver streams are: ZIP, CPIO, AR, TAR, JAR.
- === Packing a ZIP-File ===
+ === Creating a ZIP-File ===
- {{{Archive archiver = ArchiverFactory.getInstance("zip");
- archiver.add( new File("C:\\Temp\\1.html"));
- archiver.add( new File("C:\\Temp\\1.html.bz2"));
- archiver.save( new File("C:\\Temp\\ZIPTEST.zip"));}}}
+
+ {{{final OutputStream out = new FileOutputStream(output);
+ ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("zip", out);
+
+ os.putArchiveEntry(new ZipArchiveEntry("testdata/test1.xml"));
+ IOUtils.copy(new FileInputStream(file1), os);
+ os.closeArchiveEntry();
+
+ os.putArchiveEntry(new ZipArchiveEntry("testdata/test2.xml"));
+ IOUtils.copy(new FileInputStream(file2), os);
+ os.closeArchiveEntry();
+ os.close();}}}
=== Unpacking a ZIP-File ===
- {{{Archive archiver = ArchiverFactory.getInstance(
- new File("C:\\Temp\\ZIPTEST.zip"));
- archiver.unpack( new File("C:\\Temp\\unpacked\\"));}}}
+ {{{final InputStream is = new FileInputStream(input);
+ ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream("zip", is);
+ ZipArchiveEntry entry = (ZipArchiveEntry)in.getNextEntry();
+ OutputStream out = new FileOutputStream(new File(dir, entry.getName()));
+ IOUtils.copy(in, out);
+ out.close();
+ in.close();}}}
== Compressor ==
- Same goes for Compressor. At the moment there is only "bz2" support.
+ Same goes for Compressor. Compressor streams are: bz2 and gz.
=== Compressing a file ===
- {{{Compressor compressor;
- compressor = CompressorFactory.getInstance("bz2");
- compressor.compressToHere( new File("C:\\Temp\\test.tar"));}}}
+ {{{final OutputStream out = new FileOutputStream(output);
+ CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("bzip2", out);
+ IOUtils.copy(new FileInputStream(input), cos);
+ cos.close();}}}
=== Decompressing a file ===
- {{{Compressor decompressor;
- decompressor = CompressorFactory.getInstance("bz2");
- decompressor.decompressTo( new File("C:\\Temp\\asf-logo-huge.tar.bz2"),
- new File("C:\\Temp\\asf-logo-huge.tar"));}}}
+ {{{final InputStream is = new FileInputStream(input);
+ CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("bzip2", is);
+ IOUtils.copy(in, new FileOutputStream(output));
+ in.close();}}}
= FAQ =
||Add your questions/answers here.||
- = TODO =
- - Add delete features
- - Enhance implementation design
-
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org