/// <summary> /// 替换文件名 /// </summary> /// <param name="BaseOpr"></param> /// <param name="filename"></param> /// <param name="stream"></param> /// <returns></returns> public ZipFileOpr ReplaceFiles(ZipFileOpr BaseOpr, string filename, Stream stream) { string filenameLower = filename; if (BaseOpr.ZipDictionary.ContainsKey(filenameLower)) { BaseOpr.ZipDictionary.Remove(filenameLower); BaseOpr.ZipDictionary.Add(filenameLower, stream); } return(BaseOpr); }
/// <summary> /// 解压所有的文件 /// </summary> /// <returns></returns> public ZipFileOpr ZiptoFiles() { ZipInputStream s = new ZipInputStream(new FileStream(filepath, FileMode.Open)); ZipEntry fileEntry; ZipFileOpr tmpzip = new ZipFileOpr(); while ((fileEntry = s.GetNextEntry()) != null) { MemoryStream tmpstream = new MemoryStream(); int size = (int)fileEntry.Size; byte[] buffer = new byte[size]; size = s.Read(buffer, 0, size); tmpstream.Write(buffer, 0, size); tmpzip.ZipDictionary.Add(Path.GetFileName(fileEntry.Name), tmpstream); } s.Close(); return(tmpzip); }
public Stream FilesToZip(ZipFileOpr BaseOpr) { MemoryStream stream = new MemoryStream(); ZipOutputStream s = new ZipOutputStream(stream); s.UseZip64 = UseZip64.Off; foreach (KeyValuePair <string, Stream> item in BaseOpr.ZipDictionary) { s.SetLevel(-1);//设置压缩等级 ZipEntry fileEntry = new ZipEntry(item.Key); //fileEntry.Name = item.Key; Stream zipstream = item.Value; fileEntry.DateTime = DateTime.Now; s.PutNextEntry(fileEntry); s.Write(((MemoryStream)zipstream).ToArray(), 0, (int)zipstream.Length); } s.CloseEntry(); s.Finish(); s.Close(); return(stream); }