c# - Reading an unfinished gzip file -
i creating file using cygwin bash script on remote:
(echo $$ > tail.pid; exec tail -f -n+0 --retry fix.log) | gzip -c >> /faraway/log.gz
at same time, on local machine, reading /faraway/log.gz in c# using:
txtfilereader = new streamreader(new gzipstream(new filestream(@"log.gz"), filemode.open, fileaccess.read, fileshare.readwrite), compressionmode.decompress, true)); bool isdone = false; // set true when "done.txt" file appears signal log.gz completed while (true) // read until finished { if (!isdone) { if (txtfilereader.peek() == -1) // wait if file still being transferred { while (!file.exists(@"done.txt")) { thread.sleep(10000); } isdone = true; // goes wrong here when gzip closes on remote } } if ((line = txtfilereader.readline()) == null) { return ""; } }
i have indicated point in code think goes wrong.
when (peek() == -1) , gzip still running (i.e. slow transfer data) next readline works correctly, when gzip closed on remote, next readline not return correct line - returns random part of line.
later, when zcat file, see correct lines infact sent. appears losing "position" in gzipstream when gzip shuts down.
what happens when gzip closes? affect written?
Comments
Post a Comment