本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipInputStream.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# ZipInputStream.CopyTo方法的具体用法?C# ZipInputStream.CopyTo怎么用?C# ZipInputStream.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.ZipInputStream
的用法示例。
在下文中一共展示了ZipInputStream.CopyTo方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnZipFile
/// <summary>
/// 解压zip文件
/// </summary>
/// <param name="stream">本解压的文件流</param>
/// <returns>解压后的文件流</returns>
public static byte[] UnZipFile(Stream stream)
{
using (ZipInputStream inputZipStream = new ZipInputStream(stream))
{
ZipEntry theEntry = inputZipStream.GetNextEntry();
using (MemoryStream outZipStream = new MemoryStream())
{
inputZipStream.CopyTo(outZipStream);
return outZipStream.ToArray();
}
}
}
示例2: UnZipStreamIntoFolder
// part of a folder <- ZIP stream
/// <summary>
/// Unzips the specified ZIP stream to the new or existing folder. If the folder already exists, archive items will be added to the existing folder structure.
/// Files will be overwritten when there is an existing file with the same name as an archive file.
/// </summary>
public static void UnZipStreamIntoFolder( Stream sourceStream, string destinationFolderPath )
{
Directory.CreateDirectory( destinationFolderPath );
using( var zipInputStream = new ZipInputStream( sourceStream ) ) {
ZipEntry entry;
while( ( entry = zipInputStream.GetNextEntry() ) != null ) {
if( entry.IsDirectory )
Directory.CreateDirectory( EwlStatics.CombinePaths( destinationFolderPath, entry.Name ) );
else {
using( var outputStream = IoMethods.GetFileStreamForWrite( EwlStatics.CombinePaths( destinationFolderPath, entry.Name ) ) )
zipInputStream.CopyTo( outputStream );
}
}
}
}
示例3: Unzip
public static ZipContainer Unzip(Stream stream)
{
ZipEntry entry;
var zippedFiles = new List<ZippedFile>();
var source = new ZipInputStream(stream);
while ((entry = source.GetNextEntry()) != null)
{
if (entry.IsFile)
{
var destination = new MemoryStream();
source.CopyTo(destination);
zippedFiles.Add(new ZippedFile(destination, entry.Name.Replace('\\', '/')));
}
}
return new ZipContainer(zippedFiles);
}
示例4: UnZipStreamAsFileObjects
/// <summary>
/// This method completely ignores directory structure of the zip file in the source stream. The result is a flattened list of files. But, the file names do contain
/// the relative path information, so they can be used to re-create the directory structure.
/// </summary>
public static IEnumerable<RsFile> UnZipStreamAsFileObjects( Stream source )
{
var files = new List<RsFile>();
using( var zipInputStream = new ZipInputStream( source ) ) {
ZipEntry entry;
while( ( entry = zipInputStream.GetNextEntry() ) != null ) {
if( entry.IsDirectory )
continue;
using( var outputStream = new MemoryStream() ) {
zipInputStream.CopyTo( outputStream );
files.Add( new RsFile( outputStream.ToArray(), entry.Name ) );
}
}
}
return files;
}
示例5: OpenRead
public override Stream OpenRead(string fileName)
{
MemoryStream ms = null;
using (Stream stream = FileInfo.OpenRead())
using (ZipInputStream zis = new ZipInputStream(stream))
{
ZipEntry entry;
while ((entry = zis.GetNextEntry()) != null)
{
if (entry.IsFile && string.Equals(entry.Name, fileName, StringComparison.InvariantCultureIgnoreCase))
{
ms = new MemoryStream((int)entry.Size);
zis.CopyTo(ms, (int)entry.Size);
ms.Seek(0, SeekOrigin.Begin);
break;
}
}
}
return ms;
}
示例6: Inflate
/// <summary>
/// Decompresses the given data stream from its source ZIP or GZIP format.
/// </summary>
/// <param name="dataBytes"></param>
/// <returns></returns>
internal static byte[] Inflate(Stream dataStream)
{
byte[] outputBytes = null;
var zipInputStream = new ZipInputStream(dataStream);
if (zipInputStream.CanDecompressEntry)
{
MemoryStream zipoutStream = new MemoryStream();
zipInputStream.CopyTo(zipoutStream);
outputBytes = zipoutStream.ToArray();
}
else
{
try
{
dataStream.Seek(0, SeekOrigin.Begin);
#if !WINDOWS_PHONE
var gzipInputStream = new GZipInputStream(dataStream, CompressionMode.Decompress);
#else
var gzipInputStream = new GZipInputStream(dataStream);
#endif
MemoryStream zipoutStream = new MemoryStream();
gzipInputStream.CopyTo(zipoutStream);
outputBytes = zipoutStream.ToArray();
}
catch (Exception exc)
{
CCLog.Log("Error decompressing image data: " + exc.Message);
}
}
return outputBytes;
}
示例7: CheckScripts
public static void CheckScripts(Int64 build, String manifestFile)
{
var scripts = HoloXPLOR_App.Scripts;
HoloXPLOR_App._scriptsPath = HostingEnvironment.MapPath(String.Format("~/App_Data/Scripts-{0}", build));
if (!Directory.Exists(HoloXPLOR_App._scriptsPath))
{
Directory.CreateDirectory(HoloXPLOR_App._scriptsPath);
}
if (!File.Exists(Path.Combine(HoloXPLOR_App._scriptsPath, "game.xml")))
{
using (WebClient client = new WebClient())
{
// client.DownloadFile(manifestFile, Path.Combine(scriptsPath, String.Format("{0}.json", build)));
var manifest = client.DownloadString(manifestFile).FromJSON<Manifest>();
#region Download DataXML.pak
using (Stream pakStream = client.OpenRead(String.Format("{0}/{1}/{2}", manifest.WebseedUrls[HoloXPLOR_App._random.Next(manifest.WebseedUrls.Length)], manifest.KeyPrefix, "Data/DataXML.pak")))
{
using (var zipStream = new ZipInputStream(pakStream))
{
ZipEntry zipEntry = zipStream.GetNextEntry();
while (zipEntry != null)
{
String entryFileName = zipEntry.Name;
if (entryFileName.StartsWith("Scripts"))
{
String fullZipToPath = Path.Combine(HoloXPLOR_App._scriptsPath, entryFileName).Replace(@"\Scripts\", @"\");
String directoryName = Path.GetDirectoryName(fullZipToPath);
if (directoryName.Length > 0)
{
Directory.CreateDirectory(directoryName);
}
using (var ms = new MemoryStream())
{
zipStream.CopyTo(ms);
ms.Seek(0, SeekOrigin.Begin);
var xml = CryXmlSerializer.ReadStream(ms);
xml.Save(fullZipToPath);
}
}
zipEntry = zipStream.GetNextEntry();
}
}
}
#endregion
#region Download GameData.pak
using (Stream pakStream = client.OpenRead(String.Format("{0}/{1}/{2}", manifest.WebseedUrls[HoloXPLOR_App._random.Next(manifest.WebseedUrls.Length)], manifest.KeyPrefix, "Data/GameData.pak")))
{
using (var zipStream = new ZipInputStream(pakStream))
{
ZipEntry zipEntry = zipStream.GetNextEntry();
while (zipEntry != null)
{
String entryFileName = zipEntry.Name;
if (entryFileName.EndsWith(".dcb"))
{
String fullZipToPath = Path.Combine(HoloXPLOR_App._scriptsPath, "game.xml");
using (var ms = new MemoryStream())
{
zipStream.CopyTo(ms);
ms.Seek(0, SeekOrigin.Begin);
using (var br = new BinaryReader(ms))
{
var df = new DataForge.DataForge(br);
// df.GenerateXML();
df.Save(fullZipToPath);
}
}
}
zipEntry = zipStream.GetNextEntry();
}
}
}
#endregion
}
scripts = new Scripts(HoloXPLOR_App._scriptsPath);
}
scripts = scripts ?? new Scripts(HoloXPLOR_App._scriptsPath);
if (scripts.Ammo.Count > 0 &
//.........这里部分代码省略.........
示例8: AddTestCase
List<TestCase> AddTestCase(Contest contest, Problem problem, HttpPostedFileBase file)
{
if (file == null)
{
ModelState.AddModelError("File", "请选择文件");
return null;
}
Dictionary<int, byte[]> inputFiles = new Dictionary<int, byte[]>();
Dictionary<int, byte[]> outputFiles = new Dictionary<int, byte[]>();
if (new[] { "application/zip", "application/x-zip-compressed", "application/x-zip" }.Contains(file.ContentType)
|| file.ContentType == "application/octet-stream" && file.FileName.EndsWith(".zip", StringComparison.OrdinalIgnoreCase))
{
using (ZipInputStream stream = new ZipInputStream(file.InputStream))
{
ZipEntry entry;
while ((entry = stream.GetNextEntry()) != null)
{
byte[] bytes;
using (MemoryStream mem = new MemoryStream())
{
stream.CopyTo(mem);
bytes = mem.ToArray();
}
if (!DealEntry(entry.Name, bytes, inputFiles, outputFiles))
{
return null;
}
}
}
}
else if (file.FileName.EndsWith(".tgz") || file.FileName.EndsWith(".tar.gz"))
{
using (GZipStream stream = new GZipStream(file.InputStream, CompressionMode.Decompress))
{
using (TarInputStream tar = new TarInputStream(stream))
{
TarEntry entry;
while ((entry = tar.GetNextEntry()) != null)
{
byte[] bytes;
using (MemoryStream mem = new MemoryStream())
{
tar.CopyTo(mem);
bytes = mem.ToArray();
}
if (!DealEntry(entry.Name, bytes, inputFiles, outputFiles))
{
return null;
}
}
}
}
}
else if (file.FileName.EndsWith(".tar.bz2"))
{
using (BZip2InputStream stream = new BZip2InputStream(file.InputStream))
{
using (TarInputStream tar = new TarInputStream(stream))
{
TarEntry entry;
while ((entry = tar.GetNextEntry()) != null)
{
byte[] bytes;
using (MemoryStream mem = new MemoryStream())
{
tar.CopyTo(mem);
bytes = mem.ToArray();
}
if (!DealEntry(entry.Name, bytes, inputFiles, outputFiles))
{
return null;
}
}
}
}
}
else
{
ModelState.AddModelError("File", "不支持的压缩文件类型");
return null;
}
if (!inputFiles.Keys.OrderBy(x => x).SequenceEqual(outputFiles.Keys.OrderBy(x => x)))
{
ModelState.AddModelError("File", "输入与输出文件没有一一对应");
return null;
}
var testCases = inputFiles.Keys.Select(id => new TestCase
{
Input = inputFiles[id],
Data = outputFiles[id],
MemoryLimit = DEFAULT_TEST_CASE_MEMORY_LIMIT,
TimeLimit = DEFAULT_TEST_CASE_TIME_LIMIT,
Available = contest.Type == Contest.ContestType.CF ? false : true
}).ToList();
foreach (var t in testCases)
{
t.ID = problem.AddTestCase(t);
//.........这里部分代码省略.........
示例9: Inflate
/// <summary>
/// Decompresses the given data stream from its source ZIP or GZIP format.
/// </summary>
/// <param name="dataBytes"></param>
/// <returns></returns>
private static byte[] Inflate(byte[] dataBytes)
{
byte[] outputBytes = null;
var zipInputStream = new ZipInputStream(new MemoryStream(dataBytes));
if (zipInputStream.CanDecompressEntry) {
MemoryStream zipoutStream = new MemoryStream();
#if XBOX
byte[] buf = new byte[4096];
int amt = -1;
while (true)
{
amt = zipInputStream.Read(buf, 0, buf.Length);
if (amt == -1)
{
break;
}
zipoutStream.Write(buf, 0, amt);
}
#else
zipInputStream.CopyTo(zipoutStream);
#endif
outputBytes = zipoutStream.ToArray();
}
else {
try {
var gzipInputStream =
new GZipInputStream(new MemoryStream(dataBytes));
MemoryStream zipoutStream = new MemoryStream();
#if XBOX
byte[] buf = new byte[4096];
int amt = -1;
while (true)
{
amt = gzipInputStream.Read(buf, 0, buf.Length);
if (amt == -1)
{
break;
}
zipoutStream.Write(buf, 0, amt);
}
#else
gzipInputStream.CopyTo(zipoutStream);
#endif
outputBytes = zipoutStream.ToArray();
}
catch (Exception exc)
{
CCLog.Log("Error decompressing image data: " + exc.Message);
}
}
return outputBytes;
}
示例10: BulkImportSourcePages
public Result<bool> BulkImportSourcePages(string aSourcePageId, Stream file, Result<bool> aResult)
{
bool valid = TestFacsimileZipStream(file);
if (!valid)
{
aResult.Return(false);
return aResult;
}
file.Position = 0;
using (ZipInputStream zis = new ZipInputStream(file))
{
ZipEntry entry;
while ((entry = zis.GetNextEntry()) != null)
{
if (!entry.IsFile)
continue;
Match match = Regex.Match(entry.Name, @"\$facsimile_(\d+)\.jpg");
string number;
number = match.Groups[1].Value;
ISourcePage page = Context.Current.Instance.SourcePageController.CreateNew();
page.PageNumber = int.Parse(number);
page.DisplayPageNumber = int.Parse(number);
page.SourceId = aSourcePageId;
page = Context.Current.Instance.SourcePageController.Insert(page, new Result<ISourcePage>()).Wait();
using (Stream fasc = new MemoryStream())
{
zis.CopyTo(fasc, zis.Length);
fasc.Position = 0;
Context.Current.Instance.SourcePageController.AddFascimile(page.Id, fasc,fasc.Length, new Result<bool>()).Wait();
}
}
}
aResult.Return(true);
return aResult;
}