• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Compression.ZipStorer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.IO.Compression.ZipStorer的典型用法代码示例。如果您正苦于以下问题:C# ZipStorer类的具体用法?C# ZipStorer怎么用?C# ZipStorer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ZipStorer类属于System.IO.Compression命名空间,在下文中一共展示了ZipStorer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
 }
开发者ID:darkguy2008,项目名称:gamepower-free,代码行数:13,代码来源:ZIP.cs


示例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 + "/");
            }
        }
开发者ID:sauberwind,项目名称:Nov2Epub,代码行数:38,代码来源:Epubarchiver.cs


示例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();
        }
开发者ID:mikoskinen,项目名称:SubtitleProvider,代码行数:18,代码来源:ZipStorer.cs


示例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, "" );
            }
        }
开发者ID:SnakeSolidNL,项目名称:CritterBrowser,代码行数:69,代码来源:frmMain.cs


示例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();
        }
开发者ID:aswartzbaugh,项目名称:biketour,代码行数:21,代码来源:ZipStorer.cs


示例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  
        }
开发者ID:przemekwa,项目名称:SejExcelExport,代码行数:7,代码来源:OoXml.cs


示例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();
        }
开发者ID:Rameshnathan,项目名称:selenium,代码行数:18,代码来源:ZipStorer.cs


示例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();
        }
开发者ID:fragmer,项目名称:fCraft,代码行数:18,代码来源:ZipStorer.cs


示例9: ExtractFileToStream

 public bool ExtractFileToStream(ZipStorer.ZipFileEntry zipFileEntry, ref MemoryStream s)
 {
     if (Zip.ExtractFile(zipFileEntry, s))
         return true;
     return false;
 }
开发者ID:darkguy2008,项目名称:gamepower-free,代码行数:6,代码来源:ZIP.cs


示例10: ExtractFile

 public bool ExtractFile(ZipStorer.ZipFileEntry zipFileEntry, String filename)
 {
     return Zip.ExtractFile(zipFileEntry, filename);
 }
开发者ID:darkguy2008,项目名称:gamepower-free,代码行数:4,代码来源:ZIP.cs


示例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);
 }
开发者ID:darkguy2008,项目名称:gamepower-free,代码行数:7,代码来源:ZIP.cs


示例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;
            }
        }
开发者ID:wajatimur,项目名称:zixfs,代码行数:56,代码来源:Zix.cs


示例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);
                }
            }
        }
开发者ID:sauberwind,项目名称:SakuraEpubUtility,代码行数:37,代码来源:Archiver.cs


示例14: PrepareUpdate

 void PrepareUpdate()
 {
   updatePackage = ZipStorer.Open(updateLocation, System.IO.FileAccess.Read);
   updatePackageCatalog = updatePackage.ReadCentralDir();
 }
开发者ID:IntegralLee,项目名称:fomm,代码行数:5,代码来源:UpdateForm.cs


示例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;
        }
开发者ID:mikoskinen,项目名称:SubtitleProvider,代码行数:16,代码来源:ZipStorer.cs


示例16: Create

        /// <summary>
        /// Method to create a new zip storage in a stream
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="fileComment"></param>
        /// <returns>A valid ZipStorer object</returns>
        public static ZipStorer Create(Stream stream, string fileComment)
        {
            ZipStorer zip = new ZipStorer { comment = fileComment, zipFileStream = stream, access = FileAccess.Write };

            return zip;
        }
开发者ID:GMathioud,项目名称:MyCraft,代码行数:12,代码来源:ZipStorer.cs


示例17: Open

 public void Open()
 {
     Zip = ZipStorer.Open(zipFile, FileAccess.Read);
 }
开发者ID:darkguy2008,项目名称:gamepower-free,代码行数:4,代码来源:ZIP.cs


示例18: RemoveEntries

        /// <summary>
        /// Removes one of many files in storage. It creates a new Zip file.
        /// </summary>
        /// <param name="zip">Reference to the current Zip object</param>
        /// <param name="zfes">List of Entries to remove from storage</param>
        /// <returns>True if success, false if not</returns>
        /// <remarks>This method only works for storage of type FileStream</remarks>
        public static bool RemoveEntries( ref ZipStorer zip, [NotNull] List<ZipFileEntry> zfes ) {
            if( zfes == null ) throw new ArgumentNullException( "zfes" );
            if( !(zip.zipFileStream is FileStream) )
                throw new InvalidOperationException( "RemoveEntries is allowed just over streams of type FileStream" );


            //Get full list of entries
            List<ZipFileEntry> fullList = zip.ReadCentralDir();

            //In order to delete we need to create a copy of the zip file excluding the selected items
            string tempZipName = Path.GetTempFileName();
            string tempEntryName = Path.GetTempFileName();

            try {
                ZipStorer tempZip = Create( tempZipName, string.Empty );

                foreach( ZipFileEntry zfe in fullList ) {
                    if( !zfes.Contains( zfe ) ) {
                        if( zip.ExtractFile( zfe, tempEntryName ) ) {
                            tempZip.AddFile( zfe.Method, tempEntryName, zfe.FileNameInZip, zfe.Comment );
                        }
                    }
                }
                zip.Close();
                tempZip.Close();

                if( File.Exists( zip.fileName ) ) {
                    File.Replace( tempZipName, zip.fileName, null, true );
                } else {
                    File.Move( tempZipName, zip.fileName );
                }

                zip = Open( zip.fileName, zip.access );
            } catch {
                return false;
            } finally {
                if( File.Exists( tempZipName ) )
                    File.Delete( tempZipName );
                if( File.Exists( tempEntryName ) )
                    File.Delete( tempEntryName );
            }
            return true;
        }
开发者ID:fragmer,项目名称:fCraft,代码行数:50,代码来源:ZipStorer.cs


示例19: PakFile

 public PakFile(string name, string handle)
 {
     Handle = handle;
     Name = name;
     Storer = ZipStorer.Open(handle, FileAccess.Read);
 }
开发者ID:Morphan1,项目名称:Voxalia,代码行数:6,代码来源:FileHandler.cs


示例20: Create

        /// <summary>
        /// Create a new zip storage in a stream.
        /// </summary>
        /// <param name="zipStream">The stream to use to create the Zip file.</param>
        /// <param name="fileComment">General comment for Zip file.</param>
        /// <returns>A valid ZipStorer object.</returns>
        public static ZipStorer Create(Stream zipStream, string fileComment)
        {
            ZipStorer zip = new ZipStorer();
            zip.comment = fileComment;
            zip.zipFileStream = zipStream;
            zip.access = FileAccess.Write;

            return zip;
        }
开发者ID:Rameshnathan,项目名称:selenium,代码行数:15,代码来源:ZipStorer.cs



注:本文中的System.IO.Compression.ZipStorer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IsolatedStorage.IsolatedStorageFile类代码示例发布时间:2022-05-26
下一篇:
C# Compression.ZipArchiveEntry类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap