seek-bzip2 / bzip-table.c

#include <stdio.h>
#include <stdlib.h>

#include "micro-bunzip.h"

 * Read a bzip2 file from stdin and print
 * 1) The block size
 * 2) The starting offset (in BITS) of each block of compressed data
 * This does not completely uncompress the data, so does not do CRC checks,
 * (gaining 60% or so speedup), bzip2 --test can be used to verify files 
 * first if desired.
int main( int argc, char*argv[] )
    bunzip_data *bd;
	int i;
    unsigned long position_before;
    char * c;
    /* Attempt to open the bzip2 file, if successfull this consumes the 
     * entire header and moves us to the start of the first block.
    if( ! ( i = start_bunzip( &bd, 0, 0, 0 ) ) ) 
        /* Print the block size */
        fprintf( stdout, "Block size: %d\n", bd->dbufSize );
        for ( ; ; ) 
            /* Save the start of the block before reading it */
            position_before = bd->inPosBits;
            /* Read one block */
        	int i = read_bunzip_data( bd );
    	    /* Non-zero return value indicates an error, break out */
        	if( i ) break;
        	/* Print the position of the first bit in the block header */
            fprintf( stdout, "Block start at: %u\n", position_before );
    /* Free decompression buffer and bzip_data */
    if(bd->dbuf) free(bd->dbuf);
	/* Print error if required */
	if ( i )
	   fprintf(stderr,"\n%s\n", bunzip_errors[-i] ); 
    return i;	
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.