c# - GZipStream with large files doesn't work well -
i want compress large gml
files (1-10gb). wrote method this, not work well. if decompress using 7-zip windows (or else), file looks bad in end (it's not finished, xml not finished)... don't see i'm doing wrong...
private void compressfile() { string outputpath = path.combine(path.changeextension(_gmlpath, ".gz")); var buffer = new byte[1024 * 64]; using (var compressing = new gzipstream(file.openwrite(outputpath), compressionmode.compress)) { using (var file = file.openread(_gmlpath)) { var bytesread = file.read(buffer, 0, buffer.length); while (bytesread != 0) { compressing.write(buffer, 0, buffer.length); bytesread = file.read(buffer, 0, buffer.length); } } } }
[edit]
additional question: how can specify/change name of file, compressed inside gz
? it's name same input's one, there no .gml
extention:s (there in input)...
var bytesread = file.read(buffer, 0, buffer.length);
reads between 1 , 65536 bytes, but
compressing.write(buffer, 0, buffer.length);
always writes 65536 bytes, you're ending junk in file if read less 65536 bytes.
solution: write bytesread
many bytes.
compressing.write(buffer, 0, bytesread);
Comments
Post a Comment