本文整理汇总了C#中Ionic.Zip.ZipEntry.Extract方法的典型用法代码示例。如果您正苦于以下问题:C# ZipEntry.Extract方法的具体用法?C# ZipEntry.Extract怎么用?C# ZipEntry.Extract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ionic.Zip.ZipEntry
的用法示例。
在下文中一共展示了ZipEntry.Extract方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AreEqual
private bool AreEqual(ZipEntry approvedEntry, ZipEntry receivedEntry)
{
if (approvedEntry.IsDirectory && receivedEntry.IsDirectory)
{
return true;
}
using (var approvedStream = new MemoryStream())
{
using (var receivedStream = new MemoryStream())
{
approvedEntry.Extract(approvedStream);
receivedEntry.Extract(receivedStream);
var approvedBytes = approvedStream.ToArray();
var receivedBytes = receivedStream.ToArray();
var areEqual = approvedBytes == receivedBytes;
for (int i = 0; i < receivedBytes.Length && i < approvedBytes.Length; i++)
{
if (receivedBytes[i] != approvedBytes[i])
{
Logger.Event("Failed on {0}[{1}] '{2}' != '{3}'", receivedEntry.FileName, i,
(char) receivedBytes[i], (char) approvedBytes[i]);
return false;
}
}
return true;
}
}
}
示例2: GetEntryMemoryStream
public MemoryStream GetEntryMemoryStream(ZipEntry zipEntry)
{
var stream = new MemoryStream();
zipEntry.Extract(stream);
stream.Position = 0;
return stream;
}
示例3: LoadBitmap
private static Bitmap LoadBitmap(ZipEntry zipEntry)
{
MemoryStream stream = new MemoryStream();
zipEntry.Extract(stream);
stream.Position = 0;
Bitmap result = new Bitmap(stream);
stream.Dispose();
return result;
}
示例4: ExtractFileFromStream
public static string ExtractFileFromStream(ZipEntry entry)
{
var reader = new MemoryStream();
entry.Extract(reader);
reader = new MemoryStream(reader.ToArray());
var streamReader = new StreamReader(reader);
var text = streamReader.ReadToEnd();
reader.Dispose();
return text;
}
示例5: ExtractFileToStream
public static MemoryStream ExtractFileToStream(string zipSource, string filePath)
{
MemoryStream stream = new MemoryStream();
using (ZipFile zip = ZipFile.Read(zipSource))
{
var matchFile = new ZipEntry();
foreach (var file in zip.Where(file => file.FileName == filePath))
matchFile = file;
matchFile.Extract(stream);
}
return stream;
}
示例6: GenerateBitmapFromZipEntry
private BitmapSource GenerateBitmapFromZipEntry(ZipEntry entry)
{
MemoryStream stream = new MemoryStream();
entry.Extract(stream);
stream.Seek(0, SeekOrigin.Begin);
var decoder = BitmapDecoder.Create(stream,
BitmapCreateOptions.None,
BitmapCacheOption.OnLoad);
BitmapSource bitmapSource = decoder.Frames[0];
stream.Dispose();
return bitmapSource;
}
示例7: Main
static void Main(string[] args)
{
string regularplist, path, ipaname;
//App Name
Console.WriteLine("Please read the first Readme.md/n");
Console.WriteLine("Please \"XXXX\" in the place of complete Payload/XXXX.app");
ipaname = Console.ReadLine() + ".app";
//App Path
Console.WriteLine("Enter the path ipa");
path = Console.ReadLine();
ZipEntry entry = new ZipEntry();
using (ZipFile zip = ZipFile.Read(path))
{
entry = zip["Payload\\" + ipaname +"\\Info.plist"];
}
using (MemoryStream stream = new MemoryStream())
{
entry.Extract(stream);
stream.Position = 0;
var downPlist = Plist.readPlist(stream, plistType.Auto);
regularplist = Plist.writeXml(downPlist);
}
var parsedPlist = XDocument.Parse(regularplist);
String[] requiredKeys = new String[] { "DTCompiler", "CFBundleIdentifier", "CFBundleShortVersionString", "MinimumOSVersion", "CFBundleSupportedPlatforms"};
var filtredXmlData = parsedPlist.Root.Element("dict").Elements("key").Where(p => requiredKeys.Contains(p.Value)).Select(p => new
{
key = p.Value,
value = Regex.Replace(p.NextNode.ToString(), "<.*?>", string.Empty)
}).ToDictionary(k => k.key, v => v.value);
Console.WriteLine(filtredXmlData["DTCompiler"]);
Console.WriteLine(filtredXmlData["CFBundleIdentifier"]);
Console.WriteLine(filtredXmlData["CFBundleShortVersionString"]);
Console.WriteLine(filtredXmlData["CFBundleSupportedPlatforms"]);
Console.Read();
}
示例8: CompareEntry
// return:
// 0 一样
// 1 不一样
static int CompareEntry(ZipEntry e1, ZipEntry e2)
{
// 解压缩看看是否内容一样
using (Stream stream1 = new MemoryStream())
using (Stream stream2 = new MemoryStream())
{
e1.Extract(stream1);
e2.Extract(stream2);
if (stream1.Length != stream2.Length)
return 1;
// 准备从流中读出
stream1.Position = 0;
stream2.Position = 0;
while (true)
{
int nRet = stream1.ReadByte();
if (nRet == -1)
return 0;
if (nRet != stream2.ReadByte())
return 1;
}
}
}
示例9: ParsePassJson
static void ParsePassJson(PassKit p, ZipEntry e, Dictionary<string, string> discoveredHashes)
{
JObject json = null;
try
{
using (var ms = new MemoryStream())
{
e.Extract(ms);
ms.Position = 0;
var sha1 = CalculateSHA1(ms.GetBuffer(), Encoding.UTF8);
if (!discoveredHashes.ContainsKey(e.FileName.ToLower()))
discoveredHashes.Add(e.FileName.ToLower(), sha1);
using (var sr = new StreamReader(ms))
json = JObject.Parse(sr.ReadToEnd());
}
}
catch { }
if (json["passTypeIdentifier"] == null)
throw new MissingFieldException("PassKit must include a passTypeIdentifier field!");
if (json["formatVersion"] == null)
throw new MissingFieldException("PassKit must include a formatVersion field!");
if (json["organizationName"] == null)
throw new MissingFieldException("PassKit must include a organizationName field!");
if (json["serialNumber"] == null)
throw new MissingFieldException("PassKit must include a serialNumber field!");
if (json["teamIdentifier"] == null)
throw new MissingFieldException("PassKit must include a teamIdentifier field!");
if (json["description"] == null)
throw new MissingFieldException("PassKit must include a description field!");
p.PassTypeIdentifier = json["passTypeIdentifier"].Value<string>();
p.FormatVersion = json["formatVersion"].Value<int>();
p.OrganizationName = json["organizationName"].Value<string>();
p.SerialNumber = json["serialNumber"].Value<string>();
p.TeamIdentifier = json["teamIdentifier"].Value<string>();
p.Description = json["description"].Value<string>();
if (json["webServiceURL"] != null)
p.WebServiceURL = json["webServiceURL"].ToString();
if (json["authenticationToken"] != null)
p.AuthenticationToken = json["authenticationToken"].ToString();
if (json["suppressStripShine"] != null)
p.SuppressStripShine = json["suppressStripShine"].Value<bool>();
if (json["foregroundColor"] != null)
p.ForegroundColor = PKColor.Parse(json["foregroundColor"].ToString());
if (json["backgroundColor"] != null)
p.BackgroundColor = PKColor.Parse(json["backgroundColor"].ToString());
if (json["labelColor"] != null)
p.LabelColor = PKColor.Parse(json["labelColor"].ToString());
if (json["logoText"] != null)
p.LogoText = json["logoText"].Value<string>();
if (json["relevantDate"] != null)
p.RelevantDate = json["relevantDate"].Value<DateTime>();
if (json["associatedStoreIdentifiers"] != null)
{
if (p.AssociatedStoreIdentifiers == null)
p.AssociatedStoreIdentifiers = new List<string>();
var idarr = (JArray)json["associatedStoreIdentifiers"];
foreach (var ida in idarr)
p.AssociatedStoreIdentifiers.Add(ida.ToString());
}
if (json["locations"] != null && json["locations"] is JArray)
{
foreach (JObject loc in (JArray)json["locations"])
{
var pkl = new PKLocation();
if (loc["latitude"] == null)
throw new MissingFieldException("PassKit Location must include a latitude field!");
if (loc["longitude"] == null)
throw new MissingFieldException("PassKit Location must include a longitude field!");
pkl.Latitude = loc["latitude"].Value<double>();
pkl.Longitude = loc["longitude"].Value<double>();
if (loc["altitude"] != null)
pkl.Altitude = loc["altitude"].Value<double>();
if (loc["relevantText"] != null)
//.........这里部分代码省略.........
示例10: ParseManifest
static void ParseManifest(PassKit p, ZipEntry e, Dictionary<string, string> discoveredHashes)
{
JObject json = null;
try
{
using (var ms = new MemoryStream())
{
e.Extract(ms);
using (var sr = new StreamReader(ms))
{
ms.Position = 0;
var sha1 = CalculateSHA1(ms.GetBuffer(), Encoding.UTF8);
if (!discoveredHashes.ContainsKey(e.FileName.ToLower()))
discoveredHashes.Add(e.FileName.ToLower(), sha1);
var sj = sr.ReadToEnd();
json = JObject.Parse(sj);
}
}
}
catch { }
foreach (var prop in json.Properties())
{
var val = prop.Value.ToString();
var name = prop.Name.ToLower();
if (!p.Manifest.ContainsKey(name))
p.Manifest.Add(name, val);
else
p.Manifest[name] = val;
}
}
示例11: ProcessRemoveList
private static void ProcessRemoveList(ZipEntry file)
{
MemoryStream ms = new MemoryStream();
file.Extract(ms);
ms.Seek(0, SeekOrigin.Begin);
StreamReader reader = new StreamReader(ms);
string line = "";
while ((line = reader.ReadLine()) != null)
{
if (string.IsNullOrEmpty(line))
continue;
line = line.Replace("\\", "/");
string folderPath = "";
string fileSuffix = "";
string zipPath = "";
if (line.Contains("levels/"))
fileSuffix = "/";
else
fileSuffix = "_";
// We're removing a (top) folder
if (!_zipRegex.IsMatch(line))
{
folderPath = line;
// Make sure we're not deleting the root mod folder
if (folderPath.Length <= 0)
continue;
// Try removing folder from the list, if it's been previously added by an update.
try
{
_zipLists.Remove(new ZipInfo(folderPath, fileSuffix + "server.zip"));
_zipLists.Remove(new ZipInfo(folderPath, fileSuffix + "client.zip"));
Console.WriteLine("Removed {0} from zip list", folderPath);
}
catch (IndexOutOfRangeException ex)
{
Console.WriteLine(" NOTICE: {0}", ex.Message);
}
// Try removing folder/file from mod, if it's already in there.
try
{
string path = Path.Combine(_mod.ParentPath, folderPath.Replace("/", "\\"));
FileAttributes attr = File.GetAttributes(path);
if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
{
Directory.Delete(path, true);
}
else
{
File.Delete(path);
}
Console.WriteLine("Removed {0} from mod", folderPath);
}
catch (DirectoryNotFoundException ex)
{
Console.WriteLine(" NOTICE: {0}", ex.Message);
}
catch (FileNotFoundException ex)
{
Console.WriteLine(" NOTICE: {0}", ex.Message);
}
continue;
}
else
{
Match match = _zipRegex.Match(line);
folderPath = match.Groups[1].Captures[0].Value.ToLower();
zipPath = match.Groups[2].Captures[0].Value.ToLower();
// If it's a directory we need to delete it from both server and client files
// TODO: Better way than checking for dot? What if filename has dot? (this.object.con)
if (!zipPath.Contains("."))
{
AddZipCall(new ZipInfo(folderPath, fileSuffix + "server.zip"), zipPath, CallType.Remove);
AddZipCall(new ZipInfo(folderPath, fileSuffix + "client.zip"), zipPath, CallType.Remove);
continue;
}
if (_serverRegex.IsMatch(zipPath))
{
AddZipCall(new ZipInfo(folderPath, fileSuffix + "server.zip"), zipPath, CallType.Remove);
}
else
//.........这里部分代码省略.........
示例12: ExtractResource
private byte[] ExtractResource(ZipEntry entry)
{
// ZipEntry.Extract will throw an exception if the ZipFile has been
// modified. Check the VersionNeeded - if it's zero then the entry
// needs to be saved before we can extract it.
if (entry.VersionNeeded == 0)
{
this.ResetZip(true);
entry = _zip[entry.FileName];
}
using (var stream = new MemoryStream())
{
entry.Extract(stream);
return stream.ToArray();
}
}
示例13: AsycDecompress
public WaitHandle AsycDecompress(ZipEntry srcEntry)
{
if (Data == null) {
if (StreamPool.Capacity < srcEntry.UncompressedSize) StreamPool.Capacity = (int)srcEntry.UncompressedSize;
this.Data = StreamPool.Allocate();
// Extract
if (srcEntry.CompressionMethod == CompressionMethod.Deflate && srcEntry.Encryption == EncryptionAlgorithm.None) {
PropertyInfo dataPosProp = typeof(ZipEntry).GetProperty("FileDataPosition", BindingFlags.NonPublic | BindingFlags.Instance);
long dataPos = (long)dataPosProp.GetValue(srcEntry, new object[] { });
PropertyInfo streamProp = typeof(ZipEntry).GetProperty("ArchiveStream", BindingFlags.NonPublic | BindingFlags.Instance);
Stream stream = (Stream)streamProp.GetValue(srcEntry, new object[] { });
MemoryStream compressedData = StreamPool.Allocate();
compressedData.SetLength(srcEntry.CompressedSize);
stream.Seek(dataPos, SeekOrigin.Begin);
Stopwatch watch = new Stopwatch();
watch.Start();
stream.Read(compressedData.GetBuffer(), 0, (int)compressedData.Length);
watch.Stop();
TotalReadTime += watch.Elapsed;
TotalReadSizeMB += (double)compressedData.Length / 1024 / 1024;
DeflateStream decompressStream = new System.IO.Compression.DeflateStream(compressedData, CompressionMode.Decompress, true);
this.LoadDone = new ManualResetEvent(false);
Interlocked.Increment(ref activeDecompressionThreads);
ThreadPool.QueueUserWorkItem(delegate {
byte[] buffer = new byte[64 * 1024];
int readCount;
while ((readCount = decompressStream.Read(buffer, 0, buffer.Length)) != 0) {
this.Data.Write(buffer, 0, readCount);
}
decompressStream.Close();
StreamPool.Release(ref compressedData);
Interlocked.Decrement(ref activeDecompressionThreads);
this.LoadDone.Set();
});
} else {
srcEntry.Extract(this.Data);
this.LoadDone = new ManualResetEvent(true);
}
}
return this.LoadDone;
}
示例14: ExtractAssembly
private Assembly ExtractAssembly(ZipEntry entry)
{
var stream = new MemoryStream();
entry.Extract(stream);
return Assembly.Load(stream.ReadAllBytes());
}
示例15: ParseModuleStream
private void ParseModuleStream()
{
_moduleConfigEntry = ParseZipFile(_zip, out _moduleDirName);
if (_moduleConfigEntry!=null)
{
using (MemoryStream ms = new MemoryStream())
{
_moduleConfigEntry.Extract(ms);
ms.Position = 0;
_moduleInfo = ModuleInfo.Get(ms);
}
if (!string.IsNullOrEmpty(_moduleInfo.ModuleName))
{
_moduleName = _moduleInfo.ModuleName;
}
else
{
_moduleInfo.ModuleName = _moduleName;
}
}
}