diff --git a/csum-file.c b/csum-file.c
index b7174c6c056c5a8f2a800ecbcb3cdf304c0bfc3f..7088f6e93f02985f5fa5c687eb59f90ae4c13f7c 100644 (file)
--- a/csum-file.c
+++ b/csum-file.c
int sha1write(struct sha1file *f, void *buf, unsigned int count)
{
int sha1write(struct sha1file *f, void *buf, unsigned int count)
{
+ if (f->do_crc)
+ f->crc32 = crc32(f->crc32, buf, count);
while (count) {
unsigned offset = f->offset;
unsigned left = sizeof(f->buffer) - offset;
while (count) {
unsigned offset = f->offset;
unsigned left = sizeof(f->buffer) - offset;
f->fd = fd;
f->error = 0;
f->offset = 0;
f->fd = fd;
f->error = 0;
f->offset = 0;
+ f->do_crc = 0;
SHA1_Init(&f->ctx);
return f;
}
SHA1_Init(&f->ctx);
return f;
}
f->fd = fd;
f->error = 0;
f->offset = 0;
f->fd = fd;
f->error = 0;
f->offset = 0;
+ f->do_crc = 0;
SHA1_Init(&f->ctx);
return f;
}
SHA1_Init(&f->ctx);
return f;
}
-int sha1write_compressed(struct sha1file *f, void *in, unsigned int size)
+int sha1write_compressed(struct sha1file *f, void *in, unsigned int size, int level)
{
z_stream stream;
unsigned long maxsize;
void *out;
memset(&stream, 0, sizeof(stream));
{
z_stream stream;
unsigned long maxsize;
void *out;
memset(&stream, 0, sizeof(stream));
- deflateInit(&stream, zlib_compression_level);
+ deflateInit(&stream, level);
maxsize = deflateBound(&stream, size);
out = xmalloc(maxsize);
maxsize = deflateBound(&stream, size);
out = xmalloc(maxsize);
return size;
}
return size;
}
+void crc32_begin(struct sha1file *f)
+{
+ f->crc32 = crc32(0, Z_NULL, 0);
+ f->do_crc = 1;
+}
+uint32_t crc32_end(struct sha1file *f)
+{
+ f->do_crc = 0;
+ return f->crc32;
+}