i receive zip file base64 string, convert byte[], open in memory, modify content, , 'compress' new byte[] base64 string again.
my problem, don't know how 'compress' new byte[] zip format.
public string modifyzipcontent(string base64) { zippackage zippackage = null; memorystream memorystream = null; long lenght; byte[] data = convert.frombase64string(base64); byte[] buffer; byte[] newdata; int arrayoffset = 0; memorystream = new memorystream(); memorystream.write(data, 0, data.length); zippackage = (zippackage)package.open(memorystream, filemode.open); packagepartcollection zipparts = zippackage.getparts(); // awful foreach(zippackagepart zippart in zipparts) { using(stream stream = zippart.getstream()) { arrayoffset += (int)stream.length; } } newdata = new byte[arrayoffset]; // end arrayoffset = 0; foreach(zippackagepart zippart in zipparts) { using(stream stream = zippart.getstream()) { lenght = stream.length; buffer = new byte[lenght]; stream.read(buffer, 0, (int)lenght); buffer.blockcopy(buffer, 0, newdata, arrayoffset, buffer.length); arrayoffset += buffer.length; } } return convert.tobase64string(newdata); }
i haven't tested this, along these lines should work...
// requires system.io.compression using statement. byte[] bytes = new byte[256]; // byte[] here instead of empty one. using (var zipfile = zipfile.open("c:/zipfile.zip", ziparchivemode.update)) { var entry = zipfile.createentry("yourentrypathhere"); using (var stream = entry.open()) { stream.write(bytes, 0, bytes.length); } }
Comments
Post a Comment