本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipFile类的典型用法代码示例。如果您正苦于以下问题:C# ZipFile类的具体用法?C# ZipFile怎么用?C# ZipFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZipFile类属于ICSharpCode.SharpZipLib.Zip命名空间,在下文中一共展示了ZipFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Convert
public void Convert(EndianBinaryWriter writer)
{
var jbtWriter = new JbtWriter(writer);
var zf = new ZipFile(jarFile);
foreach (ZipEntry ze in zf)
{
if (!ze.IsFile) continue;
if (!ze.Name.EndsWith(".class")) continue;
var type = new CompileTypeInfo();
type.Read(zf.GetInputStream(ze));
var reader = new BinaryReader(zf.GetInputStream(ze));
var buffer = new byte[ze.Size];
reader.Read(buffer, 0, (int)ze.Size);
jbtWriter.Write(type.Name, buffer);
}
jbtWriter.Flush();
}
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:25,代码来源:JbtConverter.cs
示例2: LoadPack
public static void LoadPack(string packDir)
{
Dictionary<string, Dictionary<ushort, string>> allTextMap;
using (var z = new ZipFile(Path.Combine(packDir, "text.zip")))
{
using (var texter = new StreamReader(z.GetInputStream(z.GetEntry("text.csv")), Encoding.UTF8))
{
allTextMap = CSV.ParseCSVText(texter);
}
}
var byterList = new List<BinaryReader>();
var zipFiles = new List<ZipFile>();
foreach (var f in Directory.GetFiles(packDir, "*.zip"))
{
var name = Path.GetFileNameWithoutExtension(f);
if (name != null && !name.Equals("text"))
{
var z = new ZipFile(f);
zipFiles.Add(z);
var byter = new BinaryReader(z.GetInputStream(z.GetEntry(name)));
byterList.Add(byter);
}
}
Processor(new Stream(byterList, allTextMap));
foreach (var z in zipFiles)
{
z.Close();
}
}
开发者ID:stallboy,项目名称:configgen,代码行数:31,代码来源:CSVLoader.cs
示例3: ListZipFile
static void ListZipFile(string fileName, string fileFilter, string directoryFilter)
{
using (ZipFile zipFile = new ZipFile(fileName)) {
PathFilter localFileFilter = new PathFilter(fileFilter);
PathFilter localDirFilter = new PathFilter(directoryFilter);
if ( zipFile.Count == 0 ) {
Console.WriteLine("No entries to list");
}
else {
for ( int i = 0 ; i < zipFile.Count; ++i)
{
ZipEntry e = zipFile[i];
if ( e.IsFile ) {
string path = Path.GetDirectoryName(e.Name);
if ( localDirFilter.IsMatch(path) ) {
if ( localFileFilter.IsMatch(Path.GetFileName(e.Name)) ) {
Console.WriteLine(e.Name);
}
}
}
else if ( e.IsDirectory ) {
if ( localDirFilter.IsMatch(e.Name) ) {
Console.WriteLine(e.Name);
}
}
else {
Console.WriteLine(e.Name);
}
}
}
}
}
开发者ID:JoeCooper,项目名称:SharpZipLib.Portable,代码行数:33,代码来源:Main.cs
示例4: Basics
public void Basics()
{
const string tempName1 = "a(1).dat";
MemoryStream target = new MemoryStream();
string tempFilePath = GetTempFilePath();
Assert.IsNotNull(tempFilePath, "No permission to execute this test?");
string addFile = Path.Combine(tempFilePath, tempName1);
MakeTempFile(addFile, 1);
try {
FastZip fastZip = new FastZip();
fastZip.CreateZip(target, tempFilePath, false, @"a\(1\)\.dat", null);
MemoryStream archive = new MemoryStream(target.ToArray());
using (ZipFile zf = new ZipFile(archive)) {
Assert.AreEqual(1, zf.Count);
ZipEntry entry = zf[0];
Assert.AreEqual(tempName1, entry.Name);
Assert.AreEqual(1, entry.Size);
Assert.IsTrue(zf.TestArchive(true));
zf.Close();
}
}
finally {
File.Delete(tempName1);
}
}
开发者ID:firestrand,项目名称:SharpZipLib,代码行数:31,代码来源:ZipTests.cs
示例5: UnZip
/// <summary>
/// 解压数据。
/// </summary>
/// <param name="path"></param>
/// <param name="handler"></param>
public static void UnZip(string path, UnZipStreamHanlder handler)
{
if (File.Exists(path) && handler != null)
{
lock (typeof(ZipTools))
{
using (ZipFile zip = new ZipFile(File.Open(path, FileMode.Open, FileAccess.Read)))
{
foreach (ZipEntry entry in zip)
{
if (entry.IsFile && !string.IsNullOrEmpty(entry.Name))
{
using (Stream stream = zip.GetInputStream(entry))
{
if (stream != null)
{
handler(entry.Name, stream);
}
}
}
}
}
}
}
}
开发者ID:jeasonyoung,项目名称:csharp_sfit,代码行数:30,代码来源:ZipTools.cs
示例6: ExtendedData
public ExtendedData(string fileName, string mimeType, ZipFile zipFile, ZipEntry extendedZipEntry)
{
FileName = fileName;
MimeType = mimeType;
_ExtendedZipEntry = extendedZipEntry;
_ZipFile = zipFile;
}
开发者ID:luiseduardohdbackup,项目名称:ePubReader.Portable,代码行数:7,代码来源:ExtendedData.cs
示例7: UnZip
private static bool UnZip(string file)
{
var folder = Path.GetDirectoryName(file);
if (folder == null) return false;
using (var fs = File.OpenRead(file))
{
using (var zf = new ZipFile(fs))
{
foreach (ZipEntry entry in zf)
{
if (!entry.IsFile) continue; // Handle directories below
var outputFile = Path.Combine(folder, entry.Name);
var dir = Path.GetDirectoryName(outputFile);
if (dir == null) continue;
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
using (var stream = zf.GetInputStream(entry))
{
using (var sw = File.Create(outputFile))
{
stream.CopyTo(sw);
}
}
}
}
}
return true;
}
开发者ID:jpiolho,项目名称:sledge,代码行数:30,代码来源:UpdaterForm.cs
示例8: GetFilesToZip
/// <summary>
/// Iterate thru all the filesysteminfo objects and add it to our zip file
/// </summary>
/// <param name="fileSystemInfosToZip">a collection of files/directores</param>
/// <param name="z">our existing ZipFile object</param>
private static void GetFilesToZip(FileSystemInfo[] fileSystemInfosToZip, ZipFile z)
{
//check whether the objects are null
if (fileSystemInfosToZip != null && z != null)
{
//iterate thru all the filesystem info objects
foreach (FileSystemInfo fi in fileSystemInfosToZip)
{
//check if it is a directory
if (fi is DirectoryInfo)
{
DirectoryInfo di = (DirectoryInfo)fi;
//add the directory
z.AddDirectory(di.FullName);
//drill thru the directory to get all
//the files and folders inside it.
GetFilesToZip(di.GetFileSystemInfos(), z);
}
else
{
//add it
z.Add(fi.FullName);
}
}
}
}
开发者ID:dtafe,项目名称:vnr,代码行数:31,代码来源:SharpZipLibExtensions.cs
示例9: GetIpaPList
private static Dictionary<string, object> GetIpaPList(string filePath)
{
var plist = new Dictionary<string, object>();
var zip = new ZipInputStream(File.OpenRead(filePath));
using (var filestream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
var zipfile = new ZipFile(filestream);
ZipEntry item;
while ((item = zip.GetNextEntry()) != null)
{
Match match = Regex.Match(item.Name.ToLower(), @"Payload/([A-Za-z0-9\-. ]+)\/info.plist$",
RegexOptions.IgnoreCase);
if (match.Success)
{
var bytes = new byte[50*1024];
using (Stream strm = zipfile.GetInputStream(item))
{
int size = strm.Read(bytes, 0, bytes.Length);
using (var s = new BinaryReader(strm))
{
var bytes2 = new byte[size];
Array.Copy(bytes, bytes2, size);
plist = (Dictionary<string, object>) PlistCS.readPlist(bytes2);
}
}
break;
}
}
}
return plist;
}
开发者ID:hdxiong,项目名称:IPAParser,代码行数:35,代码来源:IOSBundle.cs
示例10: unzipDataFiles
private static void unzipDataFiles(string rootDir, string zipFile)
{
var zipFilePath = Path.Combine(rootDir, zipFile);
var unzippedDirName = zipFile.Replace(".zip", "");
var fs = System.IO.File.OpenRead(zipFilePath);
var zf = new ZipFile(fs);
foreach (ZipEntry entry in zf)
{
if (entry.IsDirectory)
{
var directoryName = Path.Combine(rootDir, entry.Name);
if (!Directory.Exists(directoryName)) Directory.CreateDirectory(directoryName);
continue;
}
var entryFileName = entry.Name;
Console.WriteLine("Unzipping {0}", entryFileName);
var buffer = new byte[4096];
var zipStream = zf.GetInputStream(entry);
var unzippedFilePath = Path.Combine(rootDir, entryFileName);
using (var fsw = System.IO.File.Create(unzippedFilePath))
{
StreamUtils.Copy(zipStream, fsw, buffer);
}
}
zf.IsStreamOwner = true;
zf.Close();
}
开发者ID:wondertrap,项目名称:TapMap,代码行数:35,代码来源:Program.cs
示例11: OpenZipFile
public void OpenZipFile()
{
ZipFile zipFile = new ZipFile(zipFileName);
Dictionary<string, TestFile> xmlFiles = new Dictionary<string, TestFile>();
// Decompress XML files
foreach(ZipEntry zipEntry in zipFile.Cast<ZipEntry>().Where(zip => zip.IsFile && zip.Name.EndsWith(".xml"))) {
Stream stream = zipFile.GetInputStream(zipEntry);
string content = new StreamReader(stream).ReadToEnd();
xmlFiles.Add(zipEntry.Name, new TestFile { Name = zipEntry.Name, Content = content });
}
// Add descriptions
foreach(TestFile metaData in xmlFiles.Values.Where(f => f.Name.StartsWith("ibm/ibm_oasis"))) {
var doc = System.Xml.Linq.XDocument.Parse(metaData.Content);
foreach(var testElem in doc.Descendants("TEST")) {
string uri = "ibm/" + testElem.Attribute("URI").Value;
string description = testElem.Value.Replace("\n ", "\n").TrimStart('\n');
if (xmlFiles.ContainsKey(uri))
xmlFiles[uri].Description = description;
}
}
// Copy canonical forms
foreach(TestFile canonical in xmlFiles.Values.Where(f => f.Name.Contains("/out/"))) {
string uri = canonical.Name.Replace("/out/", "/");
if (xmlFiles.ContainsKey(uri))
xmlFiles[uri].Canonical = canonical.Content;
}
// Copy resuts to field
this.xmlFiles.AddRange(xmlFiles.Values.Where(f => !f.Name.Contains("/out/")));
}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:31,代码来源:ParserTests.cs
示例12: GetInternalAvc
public AvcVersion GetInternalAvc(CkanModule module, string filePath, string internalFilePath = null)
{
using (var zipfile = new ZipFile(filePath))
{
return GetInternalAvc(module, zipfile, internalFilePath);
}
}
开发者ID:Zor-X-L,项目名称:CKAN,代码行数:7,代码来源:ModuleService.cs
示例13: EPubFile
public EPubFile(Stream s)
{
try
{
zip = new ZipFile(s);
string mpath = getRootFromContainer
(GetContent("META-INF/container.xml"));
OPFParser.ParseStream(GetContent(mpath), mpath,
out Manifest, out Spine);
if (Spine.TocId == null)
{
Toc = new TableOfContents();
}
else
{
string tocPath = Manifest.GetById(Spine.TocId).Linkref;
Toc = NCXParser.ParseStream(GetContent(tocPath), tocPath);
}
stream = s;
}
catch (Exception ex)
{
s.Dispose();
throw ex;
}
}
开发者ID:dlbeer,项目名称:saraswati,代码行数:30,代码来源:EPUB.cs
示例14: AddToCbz
public static bool AddToCbz(string fileName, string zipFileName)
{
if (Path.GetExtension (zipFileName).Length == 0) {
zipFileName = Path.ChangeExtension (zipFileName, ".zip");
}
ZipFile zipFile;
try {
if (File.Exists (zipFileName)) {
zipFile = new ZipFile (zipFileName);
} else {
zipFile = ZipFile.Create (zipFileName);
}
using (zipFile) {
zipFile.UseZip64 = UseZip64.Off;
zipFile.BeginUpdate ();
zipFile.Add (Path.GetFullPath (fileName));
zipFile.CommitUpdate ();
return true;
}
} catch {
return false;
}
}
开发者ID:cbowdon,项目名称:SequentialDownloader,代码行数:27,代码来源:ComicConvert.cs
示例15: ExtractZipFile
public static void ExtractZipFile(string archiveFilenameIn, string outFolder,
Func<ZipEntry, String, bool> entryCheckFunc,
string password = null)
{
ZipFile zf = null;
try
{
FileStream fs = File.OpenRead(archiveFilenameIn);
zf = new ZipFile(fs);
if (!String.IsNullOrEmpty(password))
{
zf.Password = password; // AES encrypted entries are handled automatically
}
foreach (ZipEntry zipEntry in zf)
{
if (!zipEntry.IsFile)
{
continue; // Ignore directories
}
String entryFileName = zipEntry.Name;
// to remove the folder from the entry:- entryFileName = Path.GetFileName(entryFileName);
// Optionally match entrynames against a selection list here to skip as desired.
// The unpacked length is available in the zipEntry.Size property.
// Manipulate the output filename here as desired.
String fullZipToPath = Path.Combine(outFolder, entryFileName);
string directoryName = Path.GetDirectoryName(fullZipToPath);
if (entryCheckFunc(zipEntry, fullZipToPath)) continue;
if (directoryName.Length > 0)
Directory.CreateDirectory(directoryName);
byte[] buffer = new byte[4096]; // 4K is optimum
Stream zipStream = zf.GetInputStream(zipEntry);
// Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size
// of the file, but does not waste memory.
// The "using" will close the stream even if an exception occurs.
using (FileStream streamWriter = File.Create(fullZipToPath))
{
StreamUtils.Copy(zipStream, streamWriter, buffer);
}
}
}
catch (Exception ex)
{
throw new Exception("ExtractZipFile failed", ex);
}
finally
{
if (zf != null)
{
zf.IsStreamOwner = true; // Makes close also shut the underlying stream
zf.Close(); // Ensure we release resources
}
}
}
开发者ID:ikutsin,项目名称:BinaryAnalysis.Core,代码行数:60,代码来源:ZipFunctions.cs
示例16: AreEqual
/// <summary>
/// Compares all idml's in outputPath to make sure the content.xml and styles.xml are the same
/// </summary>
public static void AreEqual(string expectFullName, string outputFullName, string msg)
{
using (var expFl = new ZipFile(expectFullName))
{
var outFl = new ZipFile(outputFullName);
foreach (ZipEntry zipEntry in expFl)
{
//TODO: designmap.xml should be tested but \\MetadataPacketPreference should be ignored as it contains the creation date.
if (!CheckFile(zipEntry.Name,"Stories,Spreads,Resources,MasterSpreads"))
continue;
if (Path.GetExtension(zipEntry.Name) != ".xml")
continue;
string outputEntry = new StreamReader(outFl.GetInputStream(outFl.GetEntry(zipEntry.Name).ZipFileIndex)).ReadToEnd();
string expectEntry = new StreamReader(expFl.GetInputStream(expFl.GetEntry(zipEntry.Name).ZipFileIndex)).ReadToEnd();
XmlDocument outputDocument = new XmlDocument();
outputDocument.XmlResolver = FileStreamXmlResolver.GetNullResolver();
outputDocument.LoadXml(outputEntry);
XmlDocument expectDocument = new XmlDocument();
outputDocument.XmlResolver = FileStreamXmlResolver.GetNullResolver();
expectDocument.LoadXml(expectEntry);
XmlDsigC14NTransform outputCanon = new XmlDsigC14NTransform();
outputCanon.Resolver = new XmlUrlResolver();
outputCanon.LoadInput(outputDocument);
XmlDsigC14NTransform expectCanon = new XmlDsigC14NTransform();
expectCanon.Resolver = new XmlUrlResolver();
expectCanon.LoadInput(expectDocument);
Stream outputStream = (Stream)outputCanon.GetOutput(typeof(Stream));
Stream expectStream = (Stream)expectCanon.GetOutput(typeof(Stream));
string errMessage = string.Format("{0}: {1} doesn't match", msg, zipEntry.Name);
Assert.AreEqual(expectStream.Length, outputStream.Length, errMessage);
FileAssert.AreEqual(expectStream, outputStream, errMessage);
}
}
}
开发者ID:neilmayhew,项目名称:pathway,代码行数:37,代码来源:IdmlTest.cs
示例17: Generate
public static Node Generate(System.IO.FileInfo fileInfo)
{
ZipFile file = new ZipFile(fileInfo.FullName);
Node node = new Node();
IDictionary<string, IList<Entry>> waiting = new Dictionary<string, IList<Entry>>();
foreach (ZipEntry zipEntry in file)
{
Entry entry = ParseEntry(zipEntry, node);
if (entry != null)
{
string name = zipEntry.Name.TrimEnd('/');
string path = name.Substring(0, name.LastIndexOf('/'));
if (!waiting.ContainsKey(path))
waiting[path] = new List<Entry>();
waiting[path].Add(entry);
}
if (zipEntry.IsDirectory && waiting.ContainsKey(zipEntry.Name.TrimEnd('/')))
{
Node dir = GetDirectory(zipEntry.Name.TrimEnd('/'), node);
if (dir != null)
{
foreach (var dirEntry in waiting[zipEntry.Name.TrimEnd('/')])
{
dir.Nodes.Add(dirEntry);
}
waiting.Remove(zipEntry.Name.TrimEnd('/'));
}
}
}
FinalizeEntries(node, waiting, fileInfo);
return node;
}
开发者ID:BGCX261,项目名称:zipdirfs-svn-to-git,代码行数:32,代码来源:ZipFileGenerator.cs
示例18: ExtractZipFile
// EXTRACT ZIP FILE
private static void ExtractZipFile(string filePath)
{
var fileReadStram = File.OpenRead(filePath);
var zipFile = new ZipFile(fileReadStram);
// USING ZIP
using (zipFile)
{
foreach (ZipEntry entry in zipFile)
{
if (entry.IsFile)
{
var entryFileName = entry.Name;
var buffer = new byte[4096];
var zipStream = zipFile.GetInputStream(entry);
var zipToPath = Path.Combine(TempFolderForExtract, entryFileName);
var directoryName = Path.GetDirectoryName(zipToPath);
if (directoryName != null && directoryName.Length > 0)
{
Directory.CreateDirectory(directoryName);
}
using (var streamWriter = File.Create(zipToPath))
{
StreamUtils.Copy(zipStream, streamWriter, buffer);
}
}
}
}
}
开发者ID:TeamCapri,项目名称:Initial,代码行数:33,代码来源:ZipToSql.cs
示例19: ExtractZipFile
private void ExtractZipFile(string filepath)
{
FileStream fileReadStream = File.OpenRead(filepath);
ZipFile zipFile = new ZipFile(fileReadStream);
using (zipFile)
{
foreach (ZipEntry zipEntry in zipFile)
{
if (zipEntry.IsFile)
{
String entryFileName = zipEntry.Name;
byte[] buffer = new byte[4096];
Stream zipStream = zipFile.GetInputStream(zipEntry);
string fullZipToPath = Path.Combine(TempFolderForExtract, entryFileName);
string directoryName = Path.GetDirectoryName(fullZipToPath);
if (directoryName.Length > 0)
{
Directory.CreateDirectory(directoryName);
}
using (FileStream streamWriter = File.Create(fullZipToPath))
{
StreamUtils.Copy(zipStream, streamWriter, buffer);
}
}
}
}
}
开发者ID:uFreezy,项目名称:Team-Bottle-Green,代码行数:30,代码来源:DataMigrator.cs
示例20: ZipExtractor
/// <summary>
/// Prepares to extract a ZIP archive contained in a stream.
/// </summary>
/// <param name="stream">The stream containing the archive data to be extracted. Will be disposed when the extractor is disposed.</param>
/// <param name="target">The path to the directory to extract into.</param>
/// <exception cref="IOException">The archive is damaged.</exception>
internal ZipExtractor([NotNull] Stream stream, [NotNull] string target)
: base(target)
{
#region Sanity checks
if (stream == null) throw new ArgumentNullException("stream");
#endregion
UnitsTotal = stream.Length;
try
{
// Read the central directory
using (var zipFile = new ZipFile(stream) {IsStreamOwner = false})
{
_centralDirectory = new ZipEntry[zipFile.Count];
for (int i = 0; i < _centralDirectory.Length; i++)
_centralDirectory[i] = zipFile[i];
}
stream.Seek(0, SeekOrigin.Begin);
_zipStream = new ZipInputStream(stream);
}
#region Error handling
catch (ZipException ex)
{
// Wrap exception since only certain exception types are allowed
throw new IOException(Resources.ArchiveInvalid, ex);
}
#endregion
}
开发者ID:modulexcite,项目名称:0install-win,代码行数:36,代码来源:ZipExtractor.cs
注:本文中的ICSharpCode.SharpZipLib.Zip.ZipFile类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论