c# - Does ZipArchiveEntry Length return wrong size? -
i'm running service on device , want send file service. easy enough, file want send comes zip file , stuff gets complicated me. i'm trying accomplish goal sending stream of inner file device, had realize i'm sending 12 bytes (which way length of inner filename extension - coincidence?) more getentry().length indicate.
am missing or doing wrong? current code (note: client valid , connected tcp-socket @ point):
system.io.compression.ziparchive zfile = system.io.compression.zipfile.open(_str_filename, system.io.compression.ziparchivemode.read); system.io.compression.ziparchiveentry zentry = zfile.getentry(_str_fwname); using (stream fs = zentry.open()) { using(networkstream ns = new networkstream(client)) { int i, counter = 0; while((i = fs.readbyte()) != -1) { ns.writebyte((byte)i); counter++; } console.writeline("bytes: " + counter); console.writeline("length file: " + zentry.length); } }
there's nil in code posted explain why getting different count @ end. whatever's going on, it's in code didn't include, or code posted not actual code you're using.
here code opens .zip file , shows stored length next actual bytes can read stored stream:
static void checkzipentries(string filename) { using (stream inputstream = new filestream(filename, filemode.open, fileaccess.read, fileshare.read | fileshare.delete)) using (ziparchive archive = new ziparchive(inputstream, ziparchivemode.read)) { foreach (ziparchiveentry entry in archive.entries) { using (stream entrystream = entry.open()) { console.writeline("entry length: {0}, stream length: {1}", entry.length, getstreamlength(entrystream)); } } } } static int getstreamlength(stream stream) { int count = 0, bytesread; byte[] rgb = new byte[1024]; while ((bytesread = stream.read(rgb, 0, rgb.length)) > 0) { count += bytesread; } homecoming count; }
when run on number of .zip files, both numbers every single archive entry identical each other.
so, guess reply question is, no it's not doing that. :)
if reply doesn't provide plenty info useful, should post code example, 1 complete, no larger absolutely necessary. see http://stackoverflow.com/help/mcve info why , how that.
c# stream zipfile
No comments:
Post a Comment