mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 18:05:42 +02:00
Make enough deflate calls to flush out all the buffered data
This commit is contained in:
@@ -63,9 +63,11 @@ struct compressor {
|
|||||||
zs.zalloc = NULL;
|
zs.zalloc = NULL;
|
||||||
zs.zfree = NULL;
|
zs.zfree = NULL;
|
||||||
zs.opaque = NULL;
|
zs.opaque = NULL;
|
||||||
|
zs.msg = (char *) "";
|
||||||
|
|
||||||
if (deflateInit(&zs, Z_DEFAULT_COMPRESSION) != Z_OK) {
|
int d = deflateInit(&zs, Z_DEFAULT_COMPRESSION);
|
||||||
fprintf(stderr, "initialize compression: %s\n", zs.msg);
|
if (d != Z_OK) {
|
||||||
|
fprintf(stderr, "initialize compression: %d %s\n", d, zs.msg);
|
||||||
exit(EXIT_IMPOSSIBLE);
|
exit(EXIT_IMPOSSIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,21 +76,32 @@ struct compressor {
|
|||||||
std::string buf;
|
std::string buf;
|
||||||
buf.resize(5000);
|
buf.resize(5000);
|
||||||
|
|
||||||
zs.next_out = (Bytef *) buf.c_str();
|
|
||||||
zs.avail_out = buf.size();
|
|
||||||
|
|
||||||
zs.next_in = zs.next_out;
|
zs.next_in = zs.next_out;
|
||||||
zs.avail_in = 0;
|
zs.avail_in = 0;
|
||||||
|
|
||||||
if (deflate(&zs, Z_FINISH) != Z_STREAM_END) {
|
while (true) {
|
||||||
fprintf(stderr, "finish compression: %s\n", zs.msg);
|
zs.next_out = (Bytef *) buf.c_str();
|
||||||
exit(EXIT_IMPOSSIBLE);
|
zs.avail_out = buf.size();
|
||||||
|
|
||||||
|
int d = deflate(&zs, Z_FINISH);
|
||||||
|
::fwrite_check(buf.c_str(), sizeof(char), zs.next_out - (Bytef *) buf.c_str(), fp, fpos, fname);
|
||||||
|
|
||||||
|
if (d == Z_OK || d == Z_BUF_ERROR) {
|
||||||
|
// it can take several calls to flush out all the buffered data
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d != Z_STREAM_END) {
|
||||||
|
fprintf(stderr, "%s: finish compression: %d %s\n", fname, d, zs.msg);
|
||||||
|
exit(EXIT_IMPOSSIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
::fwrite_check(buf.c_str(), sizeof(char), zs.next_out - (Bytef *) buf.c_str(), fp, fpos, fname);
|
int d = deflateEnd(&zs);
|
||||||
|
if (d != Z_OK) {
|
||||||
if (deflateEnd(&zs) != Z_OK) {
|
fprintf(stderr, "%s: end compression: %d %s\n", fname, d, zs.msg);
|
||||||
fprintf(stderr, "end compression: %s\n", zs.msg);
|
|
||||||
exit(EXIT_IMPOSSIBLE);
|
exit(EXIT_IMPOSSIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,8 +121,9 @@ struct compressor {
|
|||||||
zs.next_out = (Bytef *) buf.c_str();
|
zs.next_out = (Bytef *) buf.c_str();
|
||||||
zs.avail_out = buf.size();
|
zs.avail_out = buf.size();
|
||||||
|
|
||||||
if (deflate(&zs, Z_NO_FLUSH) != Z_OK) {
|
int d = deflate(&zs, Z_NO_FLUSH);
|
||||||
fprintf(stderr, "finish compression: %s\n", zs.msg);
|
if (d != Z_OK) {
|
||||||
|
fprintf(stderr, "%s: deflate: %d %s\n", fname, d, zs.msg);
|
||||||
exit(EXIT_IMPOSSIBLE);
|
exit(EXIT_IMPOSSIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3051,7 +3065,7 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *stringpool, std::atomic<
|
|||||||
}
|
}
|
||||||
compressors[j] = compressor(fp);
|
compressors[j] = compressor(fp);
|
||||||
sub[j] = &compressors[j];
|
sub[j] = &compressors[j];
|
||||||
unlink(geomname);
|
// unlink(geomname);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t useful_threads = 0;
|
size_t useful_threads = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user