本文整理汇总了C#中System.IO.Compression.ZipStorer类的典型用法代码示例。如果您正苦于以下问题:C# ZipStorer类的具体用法?C# ZipStorer怎么用?C# ZipStorer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZipStorer类属于System.IO.Compression命名空间,在下文中一共展示了ZipStorer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractFileToString
public String ExtractFileToString(ZipStorer.ZipFileEntry zipFileEntry)
{
String rv = null;
MemoryStream ms = new MemoryStream();
if (Zip.ExtractFile(zipFileEntry, ms))
{
ms.Position = 0;
rv = new StreamReader(ms).ReadToEnd().Trim();
}
ms.Close();
ms.Dispose();
return rv;
}
示例2: WriteDirToZip
//ディレクトリをzipファイルに書き込む
private static void WriteDirToZip(ZipStorer zip, DirectoryInfo srcDir, string pathInZip)
{
var files = srcDir.EnumerateFiles();
files = files.Where(e => e.Name != "mimetype"); //mimetypeファイルを除く
foreach (var file in files)
{
var ext = file.Extension;
ZipStorer.Compression compression;
//ファイル形式によって圧縮形式を変える
switch (ext)
{
case "jpg": //画像ファイルは圧縮しない(時間の無駄なので)
case "JPEG":
case "png":
case "PNG":
case "gif":
case "GIF":
compression = ZipStorer.Compression.Store;
break;
case "EPUB":
case "epub":
continue; //EPUBファイルは格納しない
default:
compression = ZipStorer.Compression.Deflate; //通常のファイルは圧縮する
break;
}
WriteFileToZip(zip,file, pathInZip + file.Name, compression);
}
//残りのディレクトリを再帰的に書き込む
var dirs = srcDir.EnumerateDirectories();
foreach (var dir in dirs)
{
WriteDirToZip(zip, dir, pathInZip + dir.Name + "/");
}
}
示例3: Open
/// <summary>
/// Method to open an existing storage
/// </summary>
/// <param name="_filename">Full path of Zip file to open</param>
/// <param name="_access">File access mode as used in FileStream constructor</param>
/// <returns></returns>
public static ZipStorer Open(string _filename, FileAccess _access)
{
ZipStorer zip = new ZipStorer();
zip.FileName = _filename;
zip.ZipFileStream = new FileStream(_filename, FileMode.Open, _access == FileAccess.Read ? FileAccess.Read : FileAccess.ReadWrite);
zip.Access = _access;
if (zip.ReadFileInfo())
return zip;
throw new System.IO.InvalidDataException();
}
示例4: AddCritterType
void AddCritterType( ZipStorer zip, CritterType crType )
{
object datafile = null;
if( !OpenCurrentDatafile( ref datafile ) )
return;
List<CritterAnimationPacked> zipFiles = new List<CritterAnimationPacked>();
foreach( CritterAnimation crAnim in crType.Animations )
{
List<string> nameList = new List<string>();
List<byte[]> bytesList = new List<byte[]>();
List<DateTime> dateList = new List<DateTime>();
string crName = crType.Name + crAnim.Name;
for( int d = 0; d <= 5; d++ )
{
if( crAnim.Dir[d] == CritterAnimationDir.None )
continue;
string ext = ".FR" + (crAnim.Full ? "M" : d.ToString());
switch( LoadedMode )
{
case LoadModeType.Directory:
string filename = openDirectory.SelectedPath + Path.DirectorySeparatorChar + crName + ext;
if( File.Exists( filename ) )
{
zipFiles.Add( new CritterAnimationPacked(
ArtCrittersZip + crName + ext,
File.ReadAllBytes( filename ),
File.GetLastWriteTime( filename )
) );
}
break;
case LoadModeType.Zip:
ZipStorer zipDatafile = (ZipStorer)datafile;
MemoryStream stream = new MemoryStream();
zipDatafile.ExtractFile( crAnim.ZipData[d], stream );
zipFiles.Add( new CritterAnimationPacked(
ArtCrittersZip + crName + ext,
stream.ToArray(),
crAnim.ZipData[d].ModifyTime ) );
break;
case LoadModeType.Dat:
DAT dat = (DAT)datafile;
zipFiles.Add( new CritterAnimationPacked(
ArtCrittersZip + crName + ext,
dat.FileList[crAnim.DatData[d]].GetData(),
DateTime.Now ) );
break;
}
if( crAnim.Full )
break;
}
}
CloseCurrentDatafile( ref datafile );
foreach( CritterAnimationPacked crAnimPacked in zipFiles )
{
MemoryStream stream = new MemoryStream( crAnimPacked.Bytes, false );
zip.AddStream( ZipStorer.Compression.Deflate, crAnimPacked.Filename, stream, crAnimPacked.Date, "" );
}
}
示例5: Open
/// <summary>
/// Method to open an existing storage from stream
/// </summary>
/// <param name="_stream">Already opened stream with zip contents</param>
/// <param name="_access">File access mode for stream operations</param>
/// <returns>A valid ZipStorer object</returns>
public static ZipStorer Open(Stream _stream, FileAccess _access)
{
if (!_stream.CanSeek && _access != FileAccess.Read)
throw new InvalidOperationException("Stream cannot seek");
ZipStorer zip = new ZipStorer();
//zip.FileName = _filename;
zip.ZipFileStream = _stream;
zip.Access = _access;
if (zip.ReadFileInfo())
return zip;
throw new System.IO.InvalidDataException();
}
示例6: gStream
public gSheet Sheet = null; // This links to a data sheet if his stream implements a data sheet
public gStream(OoXml doc, ZipStorer zip, ZipStorer.ZipFileEntry z) // This constructor is called when creating the stream from the source template
{
Document = doc; // Save a reference to the document
zfe = z; // Store the ZipFileEntry
}
示例7: Open
public static ZipStorer Open(Stream stream, FileAccess access)
{
if (!stream.CanSeek && access != FileAccess.Read)
{
throw new InvalidOperationException("Stream cannot seek");
}
ZipStorer zip = new ZipStorer();
zip.zipFileStream = stream;
zip.access = access;
if (zip.ReadFileInfo())
{
return zip;
}
throw new System.IO.InvalidDataException();
}
示例8: Open
/// <summary>
/// Method to open an existing storage from stream
/// </summary>
/// <param name="stream">Already opened stream with zip contents</param>
/// <param name="fileFileAccess">File access mode for stream operations</param>
/// <returns>A valid ZipStorer object</returns>
public static ZipStorer Open( [NotNull] Stream stream, FileAccess fileFileAccess ) {
if( stream == null ) throw new ArgumentNullException( "stream" );
if( !stream.CanSeek && fileFileAccess != FileAccess.Read )
throw new InvalidOperationException( "Stream cannot seek" );
ZipStorer zip = new ZipStorer { zipFileStream = stream, access = fileFileAccess };
if( zip.ReadFileInfo() )
return zip;
throw new InvalidDataException();
}
示例9: ExtractFileToStream
public bool ExtractFileToStream(ZipStorer.ZipFileEntry zipFileEntry, ref MemoryStream s)
{
if (Zip.ExtractFile(zipFileEntry, s))
return true;
return false;
}
示例10: ExtractFile
public bool ExtractFile(ZipStorer.ZipFileEntry zipFileEntry, String filename)
{
return Zip.ExtractFile(zipFileEntry, filename);
}
示例11: Save
public void Save()
{
Zip = ZipStorer.Create(zipFile, "GamePower Package");
Zip.EncodeUTF8 = false;
foreach (String file in Files)
Zip.AddFile(ZipStorer.Compression.Store, file, Path.GetFileName(file), String.Empty);
}
示例12: SyncToDisk
/// <summary>
///
/// </summary>
private void SyncToDisk()
{
//[i] Sync file to disk and check zix lot size
if (_zixLots.Count > 0)
{
var zlLatest = _zixLots.Last();
//[i] Need to get new file storage.
var zlFileSize = (int)new FileInfo(zlLatest.FilePath ).Length;
zlLatest.FileSize = zlFileSize;
//[i] Check zix lot file size
if (zlLatest.FileSize < (ZixSizeMax * 1024 * 1000))
{
var zlFstream = new FileStream(zlLatest.FilePath,FileMode.OpenOrCreate,FileAccess.ReadWrite,FileShare.ReadWrite );
_zixStorer = ZipStorer.Open(zlFstream, FileAccess.ReadWrite);
_zixLot = zlLatest;
}
else
{
var zlNewSeq = _zixLots.Count + 1;
var zlNewFileName = _zixStorageName + "." + ZixLotFileExt + "." + zlNewSeq ;
var zlNew = new ZixLot
{
FileName = zlNewFileName,
FilePath = _zixStoragePath + zlNewFileName,
FileSize = 0,
LotSequence = _zixLots.Count + 1
};
_zixStorer = ZipStorer.Create(_zixStoragePath + zlNew.FileName, "engine:db:zix");
_zixLots.Add(zlNew);
_zixLot = zlNew;
}
}
else
{
var zlNewFileName = _zixStorageName + "." + ZixLotFileExt + ".1";
var zlNew = new ZixLot
{
FileName = zlNewFileName,
FilePath = _zixStoragePath + zlNewFileName,
FileSize = 0,
LotSequence = 1
};
_zixStorer = ZipStorer.Create(zlNew.FilePath, "engine:db:zix");
_zixLots.Add(zlNew);
_zixLot = zlNew;
}
}
示例13: WriteEpubFilesToZip
//Epubにファイルを追加する(mimetypeを除く)
private static void WriteEpubFilesToZip(ZipStorer zip,string srcDir)
{
var files = Directory.GetFiles(srcDir, "*", SearchOption.AllDirectories); //全ファイル
var targetFiles = files.Where(e => Path.GetFileName(e).Equals("mimetype") != true) //mimetypeを除く
.Select(e => new FileInfo(e));
foreach (var targetFile in targetFiles)
{
var ext = targetFile.Extension;
var compression = new ZipStorer.Compression();
switch (ext)
{
case "jpg": //画像ファイルは圧縮しない(時間の無駄なので)
case "JPEG":
case "png":
case "PNG":
case "gif":
case "GIF":
compression = ZipStorer.Compression.Store;
break;
case "EPUB":
case "epub":
continue; //EPUBファイルは格納しない
default:
compression = ZipStorer.Compression.Deflate; //通常のファイルは圧縮する
break;
}
//対象を書き込む
using (var ms = new MemoryStream(File.ReadAllBytes(targetFile.FullName)))
{
ms.Position = 0; //ファイルの先頭からコピー
var fileNameInZip = GetRelPath(targetFile.FullName, srcDir); //zip内でのファイル名
zip.AddStream(compression, fileNameInZip, ms, DateTime.Now, string.Empty);
}
}
}
示例14: PrepareUpdate
void PrepareUpdate()
{
updatePackage = ZipStorer.Open(updateLocation, System.IO.FileAccess.Read);
updatePackageCatalog = updatePackage.ReadCentralDir();
}
示例15: Create
/// <summary>
/// Method to create a new storage file
/// </summary>
/// <param name="_filename">Full path of Zip file to create</param>
/// <param name="_comment">General comment for Zip file</param>
/// <returns></returns>
public static ZipStorer Create(string _filename, string _comment)
{
ZipStorer zip = new ZipStorer();
zip.FileName = _filename;
zip.Comment = _comment;
zip.ZipFileStream = new FileStream(_filename, FileMode.Create, FileAccess.ReadWrite);
zip.Access = FileAccess.Write;
return zip;
}