Work Requirements:
Ziphelper. CS
1 /// <summary> 2 /// compression & decompression for a single file. 3 /// </Summary> 4 public static class ziphelper 5 {6 /// <summary> 7 // compress a single file to a zipfile. 8 // </Summary> 9 // <Param name = "srcfilename"> the name of the specified source file </param> 10 // <Param name =" srcfilepath "> the path of the specified source file </param> 11 // <Param name =" zipfilepath "> the path of Specified ZIP file </param> 12 public static void compressing (string srcfilename, string srcfilepath, string zipfilepath) 13 {14 var zipstream = filehelper. openfile (zipfilepath ). result. openstreamforwriteasync (). result; 15 var srcfile = filehelper. openfile (srcfilepath ). result; 16 var streams = srcfile. openstreamforreadasync (). result; 17 var buffers = new byte [streams. length]; 18 streams. read (buffers, 0, bu Ffers. length); 19 using (zipstream) 20 {21 using (VAR ziparchive = new ziparchive (zipstream, ziparchivemode. create) 22 {23 var entry = ziparchive. createentry (srcfilename); 24 using (VAR stream = entry. open () 25 {26 var bytes = buffers; 27 stream. write (bytes, 0, bytes. length ); 28} 29} 30} 31} 32 33 34 // <summary> 35 // extract a single file 36 /// </Summary> 37 // <Param name = "zipfilepath"> compressed file path </param> 38 // <Param na Me = "desfilepath"> file storage path </param> 39 public static void decompressing (string zipfilepath, string desfilepath) 40 {41 var zipstream = filehelper. openfilestream (zipfilepath, fileaccessmode. readwrite ). result. asstream (); 42 var desfilestream = filehelper. openfilestream (desfilepath, fileaccessmode. readwrite ). result. asstream (); 43 using (VAR ziparchive = new ziparchive (zipstream, ziparchivemode. read) 44 {45 zipar Chiveentry entry = ziparchive. Entries [0]; 46 using (VAR stream = entry. open () 47 {48 While (stream. readbyte ()! =-1) 49 {50 desfilestream. writebyte (byte) stream. readbyte (); 51} 52} 53} 54 desfilestream. Dispose (); 55} 56}
View code
The method can be adjusted internally for Windows Phone.