本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipInputStream.GetNextEntry方法的典型用法代码示例。如果您正苦于以下问题:C# ZipInputStream.GetNextEntry方法的具体用法?C# ZipInputStream.GetNextEntry怎么用?C# ZipInputStream.GetNextEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.ZipInputStream
的用法示例。
在下文中一共展示了ZipInputStream.GetNextEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstallApplication
public static void InstallApplication(string zipFileName, byte[] zipFileContent)
{
string folderName = zipFileName.Replace(".zip", "").Replace(".ZIP", "");
string binFolder = HttpContext.Current.Server.MapPath("~/bin");
if (Directory.Exists(binFolder + "/" + folderName))
Directory.SetCreationTime(binFolder + "/" + folderName, DateTime.Now);
Directory.CreateDirectory(binFolder + "/" + folderName);
using (MemoryStream memStream = new MemoryStream(zipFileContent))
{
memStream.Position = 0;
using (ZipInputStream zipInput = new ZipInputStream(memStream))
{
ZipEntry current = zipInput.GetNextEntry();
while (current != null)
{
using (FileStream output = new FileStream(
binFolder + "/" + folderName + "/" + current.Name,
FileMode.Create,
FileAccess.Write))
{
byte[] buffer = new byte[current.Size];
zipInput.Read(buffer, 0, buffer.Length);
output.Write(buffer, 0, buffer.Length);
}
current = zipInput.GetNextEntry();
}
}
}
Language.Instance.SetDefaultValue("ApplicationWasInstalledRedirecting", @"
A new application was installed, and hence we had to refresh the browser
and you might need to login again...");
AjaxManager.Instance.Redirect("~/?message=ApplicationWasInstalledRedirecting");
}
示例2: TestCompressSingleMessagePart
public void TestCompressSingleMessagePart()
{
var pipeline = PipelineFactory.CreateEmptySendPipeline();
var component = new CompressMessage {DefaultZipEntryFileExtension = "xml"};
var msg = MessageHelper.CreateFromString("<testmessage1></testmessage1>");
pipeline.AddComponent(component, PipelineStage.Encode);
var result = pipeline.Execute(msg);
ZipInputStream zipInputStream = new ZipInputStream(result.BodyPart.GetOriginalDataStream());
ZipEntry zipEntry = zipInputStream.GetNextEntry();
int i = 0;
while (zipEntry != null)
{
Guid g;
Assert.IsTrue(Guid.TryParse(Path.GetFileNameWithoutExtension(zipEntry.Name), out g));
Assert.AreEqual(".xml", Path.GetExtension(zipEntry.Name));
zipEntry = zipInputStream.GetNextEntry();
i++;
}
Assert.AreEqual(1,i);
}
示例3: UnZip
public static void UnZip(this FileInfo fileInfo, string destiantionFolder)
{
using (var fileStreamIn = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read))
{
using (var zipInStream = new ZipInputStream(fileStreamIn))
{
var entry = zipInStream.GetNextEntry();
FileStream fileStreamOut = null;
while (entry != null)
{
fileStreamOut = new FileStream(destiantionFolder + @"\" + entry.Name, FileMode.Create, FileAccess.Write);
int size;
byte[] buffer = new byte[4096];
do
{
size = zipInStream.Read(buffer, 0, buffer.Length);
fileStreamOut.Write(buffer, 0, size);
} while (size > 0);
fileStreamOut.Close();
entry = zipInStream.GetNextEntry();
}
if (fileStreamOut != null)
fileStreamOut.Close();
zipInStream.Close();
}
fileStreamIn.Close();
}
}
示例4: TestCompressWithContentType
public void TestCompressWithContentType()
{
var pipeline = PipelineFactory.CreateEmptySendPipeline();
var component = new CompressMessage();
var msgPart2 = MessageHelper.CreatePartFromString("<testmessage2></testmessage2>");
var msgPart3 = MessageHelper.CreatePartFromString("<testmessage3></testmessage3>");
msgPart2.ContentType = "application/xml";
msgPart3.ContentType = "application/xml";
var msg = MessageHelper.CreateFromString("<testmessage1></testmessage1>");
msg.AddPart("invoice2", msgPart2, false);
msg.AddPart("invoice3", msgPart3, false);
msg.BodyPart.ContentType = "application/xml";
pipeline.AddComponent(component, PipelineStage.Encode);
var result = pipeline.Execute(msg);
ZipInputStream zipInputStream = new ZipInputStream(result.BodyPart.GetOriginalDataStream());
ZipEntry zipEntry = zipInputStream.GetNextEntry();
while (zipEntry != null)
{
Guid g;
Assert.IsTrue(Guid.TryParse(Path.GetFileNameWithoutExtension(zipEntry.Name), out g));
Assert.AreEqual(".xml", Path.GetExtension(zipEntry.Name));
zipEntry = zipInputStream.GetNextEntry();
}
}
示例5: WriteAllFilesToDb
private static void WriteAllFilesToDb(MemoryStream stream)
{
ZipInputStream fileFromMemory = new ZipInputStream(stream);
var entry = fileFromMemory.GetNextEntry();
while (entry != null)
{
WriteFileToDb(fileFromMemory);
entry = fileFromMemory.GetNextEntry();
}
}
示例6: RestoreFromFile
private void RestoreFromFile(Stream file)
{
//
//
using (var store = IsolatedStorageFile.GetUserStoreForApplication()) {
using (var zip = new ZipInputStream(file)) {
try {
while (true) {
var ze = zip.GetNextEntry();
if (ze == null) break;
using (var f = new IsolatedStorageFileStream(ze.Name, FileMode.Create, store)) {
var fs = new byte[ze.Size];
zip.Read(fs, 0, fs.Length);
f.Write(fs, 0, fs.Length);
}
}
} catch {
lblLastBackup.Text = StringResources.BackupAndRestorePage_Messages_RestoreFailed;
App.ToastMe(StringResources.BackupAndRestorePage_Messages_RestoreFailed);
return;
} finally {
file.Close();
ClearOldBackupFiles();
App.ViewModel.IsRvDataChanged = true;
}
}
}
lblLastBackup.Text = StringResources.BackupAndRestorePage_Messages_RestoreSuccess;
App.ToastMe(StringResources.BackupAndRestorePage_Messages_RestoreSuccess);
}
示例7: Extract
public void Extract(string path, string dest_dir)
{
ZipInputStream zipstream = new ZipInputStream(new FileStream( path, FileMode.Open));
ZipEntry theEntry;
while ((theEntry = zipstream.GetNextEntry()) != null) {
string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
// create directory
if (directoryName != String.Empty)
Directory.CreateDirectory(directoryName);
if (fileName != String.Empty) {
FileStream streamWriter = File.Create( Path.Combine( dest_dir, theEntry.Name) );
int size = 0;
byte[] buffer = new byte[2048];
while ((size = zipstream.Read(buffer, 0, buffer.Length)) > 0) {
streamWriter.Write(buffer, 0, size);
}
streamWriter.Close();
}
}
zipstream.Close();
}
示例8: Main
public static void Main(string[] args)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null) {
Console.WriteLine("Name : {0}", theEntry.Name);
Console.WriteLine("Date : {0}", theEntry.DateTime);
Console.WriteLine("Size : (-1, if the size information is in the footer)");
Console.WriteLine(" Uncompressed : {0}", theEntry.Size);
Console.WriteLine(" Compressed : {0}", theEntry.CompressedSize);
int size = 2048;
byte[] data = new byte[2048];
Console.Write("Show Entry (y/n) ?");
if (Console.ReadLine() == "y") {
// System.IO.Stream st = File.Create("G:\\a.tst");
while (true) {
size = s.Read(data, 0, data.Length);
// st.Write(data, 0, size);
if (size > 0) {
Console.Write(new ASCIIEncoding().GetString(data, 0, size));
} else {
break;
}
}
// st.Close();
}
Console.WriteLine();
}
s.Close();
}
示例9: Parse
public override string Parse()
{
if (!File.Exists(Context.Path))
throw new FileNotFoundException("File " + Context.Path + " is not found");
StringBuilder sb = new StringBuilder();
using (ZipInputStream zipStream = new ZipInputStream(File.OpenRead(Context.Path)))
{
ZipEntry entry = zipStream.GetNextEntry();
while (entry != null)
{
sb.AppendLine(entry.Name);
entry = zipStream.GetNextEntry();
}
}
return sb.ToString();
}
示例10: ImportMethod
protected override void ImportMethod()
{
using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORT, STR_DOWNLOAD, 1, 0))
{
using (System.IO.TemporaryFile tmp = new System.IO.TemporaryFile(true))
using (System.Net.WebClient wc = new System.Net.WebClient())
{
wc.DownloadFile("http://www.globalcaching.eu/service/cachedistance.aspx?country=Netherlands&prefix=GC", tmp.Path);
using (var fs = System.IO.File.OpenRead(tmp.Path))
using (ZipInputStream s = new ZipInputStream(fs))
{
ZipEntry theEntry = s.GetNextEntry();
byte[] data = new byte[1024];
if (theEntry != null)
{
StringBuilder sb = new StringBuilder();
while (true)
{
int size = s.Read(data, 0, data.Length);
if (size > 0)
{
if (sb.Length == 0 && data[0] == 0xEF && size > 2)
{
sb.Append(System.Text.ASCIIEncoding.UTF8.GetString(data, 3, size - 3));
}
else
{
sb.Append(System.Text.ASCIIEncoding.UTF8.GetString(data, 0, size));
}
}
else
{
break;
}
}
XmlDocument doc = new XmlDocument();
doc.LoadXml(sb.ToString());
XmlElement root = doc.DocumentElement;
XmlNodeList nl = root.SelectNodes("wp");
if (nl != null)
{
Core.Geocaches.AddCustomAttribute(CUSTOM_ATTRIBUTE);
foreach (XmlNode n in nl)
{
var gc = Utils.DataAccess.GetGeocache(Core.Geocaches, n.Attributes["code"].InnerText);
if (gc != null)
{
string dist = Utils.Conversion.StringToDouble(n.Attributes["dist"].InnerText).ToString("000.0");
gc.SetCustomAttribute(CUSTOM_ATTRIBUTE, dist);
}
}
}
}
}
}
}
}
示例11: UnZip
protected Stream UnZip(Stream input)
{
var zipInputStream = new ZipInputStream(input);
if (zipInputStream.GetNextEntry() == null)
throw new ZipException("Can't unzip archive.");
return zipInputStream;
}
示例12: UnZip
/// <summary>
/// 解压缩文件(压缩文件中含有子目录)
/// </summary>
/// <param name="zipfilepath">待解压缩的文件路径</param>
/// <param name="unzippath">解压缩到指定目录</param>
/// <returns>解压后的文件列表</returns>
public List<string> UnZip(string zipfilepath, string unzippath)
{
//解压出来的文件列表
List<string> unzipFiles = new List<string>();
//检查输出目录是否以“\\”结尾
if (unzippath.EndsWith("\\") == false || unzippath.EndsWith(":\\") == false)
{
unzippath += "\\";
}
ZipInputStream s = new ZipInputStream(File.OpenRead(zipfilepath));
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(unzippath);
string fileName = Path.GetFileName(theEntry.Name);
//生成解压目录【用户解压到硬盘根目录时,不需要创建】
if (!string.IsNullOrEmpty(directoryName))
{
Directory.CreateDirectory(directoryName);
}
if (fileName != String.Empty)
{
//如果文件的压缩后大小为0那么说明这个文件是空的,因此不需要进行读出写入
if (theEntry.CompressedSize == 0)
break;
//解压文件到指定的目录
directoryName = Path.GetDirectoryName(unzippath + theEntry.Name);
//建立下面的目录和子目录
Directory.CreateDirectory(directoryName);
//记录导出的文件
unzipFiles.Add(unzippath + theEntry.Name);
FileStream streamWriter = File.Create(unzippath + theEntry.Name);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
}
}
s.Close();
GC.Collect();
return unzipFiles;
}
示例13: Unzip
// 압축을 해제한다.
private void Unzip(string zipfile)
{
// 풀고자 하는 압축 파일 이름
ZipInputStream s = new ZipInputStream(File.OpenRead(zipfile));
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
// 압축을 풀고자 하는 대상 폴더 이름이 "C:\test" 인 경우
string fullname = @"C:\zipTest" + theEntry.Name;
string directoryName = Path.GetDirectoryName(fullname);
string fileName = Path.GetFileName(fullname);
if (!Directory.Exists(directoryName)) Directory.CreateDirectory(directoryName);
if (fileName != String.Empty)
{
FileStream streamWriter = File.Create(fullname);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0) streamWriter.Write(data, 0, size);
else break;
}
streamWriter.Close();
}
}
s.Close();
}
示例14: Main
public static void Main(string[] args)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null) {
Console.WriteLine(theEntry.Name);
string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
// create directory
Directory.CreateDirectory(directoryName);
if (fileName != String.Empty) {
FileStream streamWriter = File.Create(theEntry.Name);
int size = 2048;
byte[] data = new byte[2048];
while (true) {
size = s.Read(data, 0, data.Length);
if (size > 0) {
streamWriter.Write(data, 0, size);
} else {
break;
}
}
streamWriter.Close();
}
}
s.Close();
}
示例15: Add
public override void Add (string path)
{
using (var file_stream = new FileStream (path, FileMode.Open, FileAccess.Read))
using (var zip_stream = new ZipInputStream (file_stream)) {
ZipEntry entry;
while ((entry = zip_stream.GetNextEntry ()) != null) {
if (!entry.IsFile) {
continue;
}
var extension = Path.GetExtension (entry.Name);
if (!parser_for_parts.SupportedFileExtensions.Contains (extension)) {
continue;
}
using (var out_stream = new MemoryStream ()) {
int size;
var buffer = new byte[2048];
do {
size = zip_stream.Read (buffer, 0, buffer.Length);
out_stream.Write (buffer, 0, size);
} while (size > 0);
out_stream.Seek (0, SeekOrigin.Begin);
try {
parser_for_parts.Add (out_stream, entry.Name);
} catch (NotSupportedException) {
}
}
}
}
}