Posts Tagged zip

using libzip

jar tf too slow

So I recently had occassion to notice that “jar tf” was much slower than “unzip -l”

% for f in 0 1 2 3 4 5 6 7 8 9 ; do time jar tf velocity-dvsl-0.43.20020711.010949.jar > a ; done 2>&1 | grep ^real | cut -f2- -dm | cut -f1 -ds | xargs | tr ' ' + | bc -l
2.750
% for f in 0 1 2 3 4 5 6 7 8 9 ; do time unzip -l velocity-dvsl-0.43.20020711.010949.jar > u ; done 2>&1 | grep ^real | cut -f2- -dm | cut -f1 -ds | xargs | tr ' ' + | bc -l
.096

So the jar command is almost 3 times slower! But it prints the list of contents in a simple format I like. Instead of grep/cut/sed’ing up, I decided to write a custom application.

zip_print.c

% sudo apt-get install libzip-dev libzip1

Here are the highlights:

#include <zip.h>
...
int
main( int argc, char *argv[] ) {
  struct zip *zip_ptr;
....
  for ( i = 1 ; i < argc ; i++ ) {
        path = argv[ i ];
        zip_ptr = zip_open( path, ZIP_CHECKCONS, &errorp );
...
        max = zip_get_num_files( zip_ptr );
        for ( j = 0 ; j < max ; j++ ) {
            printf( "%s\n", zip_get_name( zip_ptr, j, ZIP_FL_UNCHANGED ) );
        }
...
       zip_close( zip_ptr );
% for f in 0 1 2 3 4 5 6 7 8 9 ; do time ./zip_print velocity-dvsl-0.43.20020711.010949.jar > b ; done 2>&1 | grep ^real | cut -f2- -dm | cut -f1 -ds | xargs | tr ' ' + | bc -l
.092
% diff a b

Now I’m not going to claim zip_print is faster than “zip -l”… that .004 is basicly bunk, but it is certainly faster than “jar tf”

Leave a Comment