C# - How to read a text file from GZip -
here problem, i'm trying make minecraft classic server , i'm using text system make allow list each map, problem text system makes file each map , got around 15k maps in total, if 1k of players add allow list maps, hard upload / move server host. want make zip file in main folder of software , add each text file , making readable system, want know how read file gzip, , how compress files also.
thanks
details on how use gzip compress , decompress. after decompression, can use streamreader() class read contents of file (.net 4.0).
using system; using system.io; using system.io.compression; namespace zip { public class program { public static void main() { string directorypath = @"c:\users\public\reports"; directoryinfo directoryselected = new directoryinfo(directorypath); foreach (fileinfo filetocompress in directoryselected.getfiles()) { compress(filetocompress); } foreach (fileinfo filetodecompress in directoryselected.getfiles("*.gz")) { decompress(filetodecompress); } } public static void compress(fileinfo filetocompress) { using (filestream originalfilestream = filetocompress.openread()) { if ((file.getattributes(filetocompress.fullname) & fileattributes.hidden) != fileattributes.hidden & filetocompress.extension != ".gz") { using (filestream compressedfilestream = file.create(filetocompress.fullname + ".gz")) { using (gzipstream compressionstream = new gzipstream(compressedfilestream, compressionmode.compress)) { originalfilestream.copyto(compressionstream); console.writeline("compressed {0} {1} {2} bytes.", filetocompress.name, filetocompress.length.tostring(), compressedfilestream.length.tostring()); } } } } } public static void decompress(fileinfo filetodecompress) { using (filestream originalfilestream = filetodecompress.openread()) { string currentfilename = filetodecompress.fullname; string newfilename = currentfilename.remove(currentfilename.length - filetodecompress.extension.length); using (filestream decompressedfilestream = file.create(newfilename)) { using (gzipstream decompressionstream = new gzipstream(originalfilestream, compressionmode.decompress)) { decompressionstream.copyto(decompressedfilestream); console.writeline("decompressed: {0}", filetodecompress.name); } } } } } }
Comments
Post a Comment