Add statistics: track offset in compressed and uncompressed archive,
provide an interface for the client to query this information.
This commit is contained in:
parent
d6382fb160
commit
4f6d19ce20
@ -257,6 +257,11 @@ void archive_write_finish(struct archive *);
|
||||
* Accessor functions to read/set various information in
|
||||
* the struct archive object:
|
||||
*/
|
||||
/* Bytes written after compression or read before decompression. */
|
||||
int64_t archive_position_compressed(struct archive *);
|
||||
/* Bytes written to compressor or read from decompressor. */
|
||||
int64_t archive_position_uncompressed(struct archive *);
|
||||
|
||||
const char *archive_compression_name(struct archive *);
|
||||
int archive_compression(struct archive *);
|
||||
int archive_errno(struct archive *);
|
||||
|
@ -257,6 +257,11 @@ void archive_write_finish(struct archive *);
|
||||
* Accessor functions to read/set various information in
|
||||
* the struct archive object:
|
||||
*/
|
||||
/* Bytes written after compression or read before decompression. */
|
||||
int64_t archive_position_compressed(struct archive *);
|
||||
/* Bytes written to compressor or read from decompressor. */
|
||||
int64_t archive_position_uncompressed(struct archive *);
|
||||
|
||||
const char *archive_compression_name(struct archive *);
|
||||
int archive_compression(struct archive *);
|
||||
int archive_errno(struct archive *);
|
||||
|
@ -99,6 +99,8 @@ struct archive {
|
||||
|
||||
/* Position in UNCOMPRESSED data stream. */
|
||||
off_t file_position;
|
||||
/* Position in COMPRESSED data stream. */
|
||||
off_t raw_position;
|
||||
/* File offset of beginning of most recently-read header. */
|
||||
off_t header_position;
|
||||
|
||||
|
@ -325,6 +325,7 @@ drive_decompressor(struct archive *a, struct private_data *state)
|
||||
a->compression_name);
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
a->raw_position += ret;
|
||||
state->stream.avail_in = ret;
|
||||
}
|
||||
|
||||
|
@ -335,6 +335,7 @@ drive_decompressor(struct archive *a, struct private_data *state)
|
||||
a->compression_name);
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
a->raw_position += ret;
|
||||
state->stream.avail_in = ret;
|
||||
}
|
||||
|
||||
|
@ -180,6 +180,7 @@ archive_decompressor_none_read_ahead(struct archive *a, const void **buff,
|
||||
state->end_of_file = 1;
|
||||
break;
|
||||
}
|
||||
a->raw_position += bytes_read;
|
||||
state->client_total = bytes_read;
|
||||
state->client_avail = state->client_total;
|
||||
state->client_next = state->client_buff;
|
||||
|
@ -76,6 +76,26 @@ archive_compression_name(struct archive *a)
|
||||
return (a->compression_name);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return a count of the number of compressed bytes processed.
|
||||
*/
|
||||
int64_t
|
||||
archive_position_compressed(struct archive *a)
|
||||
{
|
||||
return (a->raw_position);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a count of the number of uncompressed bytes processed.
|
||||
*/
|
||||
int64_t
|
||||
archive_position_uncompressed(struct archive *a)
|
||||
{
|
||||
return (a->file_position);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
archive_set_error(struct archive *a, int error_number, const char *fmt, ...)
|
||||
{
|
||||
|
@ -172,6 +172,7 @@ archive_compressor_bzip2_write(struct archive *a, const void *buff,
|
||||
state->stream.avail_in = length;
|
||||
if (drive_compressor(a, state, 0))
|
||||
return (-1);
|
||||
a->file_position += length;
|
||||
return (length);
|
||||
}
|
||||
|
||||
@ -244,6 +245,7 @@ archive_compressor_bzip2_finish(struct archive *a)
|
||||
ret = (a->client_writer)(a, a->client_data, state->compressed,
|
||||
block_length);
|
||||
|
||||
a->raw_position += ret;
|
||||
if (ret != 0)
|
||||
goto cleanup;
|
||||
|
||||
@ -295,6 +297,7 @@ drive_compressor(struct archive *a, struct private_data *state, int finishing)
|
||||
state->compressed_buffer_size - ret);
|
||||
}
|
||||
|
||||
a->raw_position += ret;
|
||||
state->stream.next_out = state->compressed +
|
||||
state->compressed_buffer_size - ret;
|
||||
state->stream.avail_out = ret;
|
||||
|
@ -200,6 +200,7 @@ archive_compressor_gzip_write(struct archive *a, const void *buff,
|
||||
if ((ret = drive_compressor(a, state, 0)) != ARCHIVE_OK)
|
||||
return (ret);
|
||||
|
||||
a->file_position += length;
|
||||
return (length);
|
||||
}
|
||||
|
||||
@ -270,6 +271,7 @@ archive_compressor_gzip_finish(struct archive *a)
|
||||
if (tocopy < 8) {
|
||||
ret = (a->client_writer)(a, a->client_data, state->compressed,
|
||||
state->compressed_buffer_size);
|
||||
a->raw_position += ret;
|
||||
state->stream.next_out = state->compressed;
|
||||
state->stream.avail_out = state->compressed_buffer_size;
|
||||
memcpy(state->stream.next_out, trailer + tocopy, 8-tocopy);
|
||||
|
@ -131,7 +131,8 @@ archive_compressor_none_write(struct archive *a, const void *vbuff,
|
||||
if (state->avail == 0) {
|
||||
ret = (a->client_writer)(a, a->client_data,
|
||||
state->buffer, state->buffer_size);
|
||||
/* TODO: if ret < state->buffer_size */
|
||||
/* XXX TODO: if ret < state->buffer_size XXX */
|
||||
a->raw_position += ret;
|
||||
state->next = state->buffer;
|
||||
state->avail = state->buffer_size;
|
||||
}
|
||||
@ -145,6 +146,7 @@ archive_compressor_none_write(struct archive *a, const void *vbuff,
|
||||
buff += to_copy;
|
||||
remaining -= to_copy;
|
||||
}
|
||||
a->file_position += length;
|
||||
return (length);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user