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

C# Zip.ZipHelperStream类代码示例

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

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



ZipHelperStream类属于ICSharpCode.SharpZipLib.Zip命名空间,在下文中一共展示了ZipHelperStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SetData

 public void SetData(byte[] data, int index, int count)
 {
     using (MemoryStream stream = new MemoryStream(data, index, count, false))
     {
         using (ZipHelperStream stream2 = new ZipHelperStream(stream))
         {
             stream2.ReadLEInt();
             while (stream2.Position < stream2.Length)
             {
                 int num = stream2.ReadLEShort();
                 int num2 = stream2.ReadLEShort();
                 if (num == 1)
                 {
                     if (num2 >= 0x18)
                     {
                         long fileTime = stream2.ReadLELong();
                         this._lastModificationTime = DateTime.FromFileTime(fileTime);
                         long num4 = stream2.ReadLELong();
                         this._lastAccessTime = DateTime.FromFileTime(num4);
                         long num5 = stream2.ReadLELong();
                         this._createTime = DateTime.FromFileTime(num5);
                     }
                     return;
                 }
                 stream2.Seek((long) num2, SeekOrigin.Current);
             }
         }
     }
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:29,代码来源:NTTaggedData.cs


示例2: GetData

 public byte[] GetData()
 {
     byte[] buffer;
     using (MemoryStream stream = new MemoryStream())
     {
         using (ZipHelperStream stream2 = new ZipHelperStream(stream))
         {
             stream2.IsStreamOwner = false;
             stream2.WriteByte((byte) this._flags);
             if (((byte) (this._flags & Flags.ModificationTime)) != 0)
             {
                 DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 TimeSpan span = (TimeSpan) (this._modificationTime.ToUniversalTime() - time.ToUniversalTime());
                 int totalSeconds = (int) span.TotalSeconds;
                 stream2.WriteLEInt(totalSeconds);
             }
             if (((byte) (this._flags & Flags.AccessTime)) != 0)
             {
                 DateTime time2 = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 TimeSpan span2 = (TimeSpan) (this._lastAccessTime.ToUniversalTime() - time2.ToUniversalTime());
                 int num2 = (int) span2.TotalSeconds;
                 stream2.WriteLEInt(num2);
             }
             if (((byte) (this._flags & Flags.CreateTime)) != 0)
             {
                 DateTime time3 = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 TimeSpan span3 = (TimeSpan) (this._createTime.ToUniversalTime() - time3.ToUniversalTime());
                 int num3 = (int) span3.TotalSeconds;
                 stream2.WriteLEInt(num3);
             }
             buffer = stream.ToArray();
         }
     }
     return buffer;
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:35,代码来源:ExtendedUnixData.cs


示例3: SetData

 public void SetData(byte[] data, int index, int count)
 {
     using (MemoryStream stream = new MemoryStream(data, index, count, false))
     {
         using (ZipHelperStream stream2 = new ZipHelperStream(stream))
         {
             this._flags = (Flags) ((byte) stream2.ReadByte());
             if ((((byte) (this._flags & Flags.ModificationTime)) != 0) && (count >= 5))
             {
                 int seconds = stream2.ReadLEInt();
                 DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 this._modificationTime = (time.ToUniversalTime() + new TimeSpan(0, 0, 0, seconds, 0)).ToLocalTime();
             }
             if (((byte) (this._flags & Flags.AccessTime)) != 0)
             {
                 int num2 = stream2.ReadLEInt();
                 DateTime time3 = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 this._lastAccessTime = (time3.ToUniversalTime() + new TimeSpan(0, 0, 0, num2, 0)).ToLocalTime();
             }
             if (((byte) (this._flags & Flags.CreateTime)) != 0)
             {
                 int num3 = stream2.ReadLEInt();
                 DateTime time5 = new DateTime(0x7b2, 1, 1, 0, 0, 0);
                 this._createTime = (time5.ToUniversalTime() + new TimeSpan(0, 0, 0, num3, 0)).ToLocalTime();
             }
         }
     }
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:28,代码来源:ExtendedUnixData.cs


示例4: GetData

 public byte[] GetData()
 {
     byte[] buffer;
     using (MemoryStream stream = new MemoryStream())
     {
         using (ZipHelperStream stream2 = new ZipHelperStream(stream))
         {
             stream2.IsStreamOwner = false;
             stream2.WriteLEInt(0);
             stream2.WriteLEShort(1);
             stream2.WriteLEShort(0x18);
             stream2.WriteLELong(this._lastModificationTime.ToFileTime());
             stream2.WriteLELong(this._lastAccessTime.ToFileTime());
             stream2.WriteLELong(this._createTime.ToFileTime());
             buffer = stream.ToArray();
         }
     }
     return buffer;
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:19,代码来源:NTTaggedData.cs


示例5: GetData

 public byte[] GetData()
 {
     byte[] result;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         using (ZipHelperStream zipHelperStream = new ZipHelperStream(memoryStream))
         {
             zipHelperStream.IsStreamOwner = false;
             zipHelperStream.WriteLEInt(0);
             zipHelperStream.WriteLEShort(1);
             zipHelperStream.WriteLEShort(24);
             zipHelperStream.WriteLELong(this._lastModificationTime.ToFileTime());
             zipHelperStream.WriteLELong(this._lastAccessTime.ToFileTime());
             zipHelperStream.WriteLELong(this._createTime.ToFileTime());
             result = memoryStream.ToArray();
         }
     }
     return result;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:19,代码来源:NTTaggedData.cs


示例6: LocateBlockWithSignature

		// NOTE this returns the offset of the first byte after the signature.
		long LocateBlockWithSignature(int signature, long endLocation, int minimumBlockSize, int maximumVariableData)
		{
			using ( ZipHelperStream les = new ZipHelperStream(baseStream_) ) {
				return les.LocateBlockWithSignature(signature, endLocation, minimumBlockSize, maximumVariableData);
			}
		}
开发者ID:jamesbascle,项目名称:SharpZipLib,代码行数:7,代码来源:ZipFile.cs


示例7: UpdateCommentOnly

		void UpdateCommentOnly()
		{
			long baseLength = baseStream_.Length;

			ZipHelperStream updateFile = null;

			if ( archiveStorage_.UpdateMode == FileUpdateMode.Safe ) {
				Stream copyStream = archiveStorage_.MakeTemporaryCopy(baseStream_);
				updateFile = new ZipHelperStream(copyStream);
				updateFile.IsStreamOwner = true;

				baseStream_.Close();
				baseStream_ = null;
			}
			else {
				if (archiveStorage_.UpdateMode == FileUpdateMode.Direct) {
					// TODO: archiveStorage wasnt originally intended for this use.
					// Need to revisit this to tidy up handling as archive storage currently doesnt 
					// handle the original stream well.
					// The problem is when using an existing zip archive with an in memory archive storage.
					// The open stream wont support writing but the memory storage should open the same file not an in memory one.

					// Need to tidy up the archive storage interface and contract basically.
					baseStream_ = archiveStorage_.OpenForDirectUpdate(baseStream_);
					updateFile = new ZipHelperStream(baseStream_);
				}
				else {
					baseStream_.Close();
					baseStream_ = null;
					updateFile = new ZipHelperStream(Name);
				}
			}

			using ( updateFile ) {
				long locatedCentralDirOffset = 
					updateFile.LocateBlockWithSignature(ZipConstants.EndOfCentralDirectorySignature, 
														baseLength, ZipConstants.EndOfCentralRecordBaseSize, 0xffff);
				if ( locatedCentralDirOffset < 0 ) {
					throw new ZipException("Cannot find central directory");
				}

				const int CentralHeaderCommentSizeOffset = 16;
				updateFile.Position += CentralHeaderCommentSizeOffset;

				byte[] rawComment = newComment_.RawComment;

				updateFile.WriteLEShort(rawComment.Length);
				updateFile.Write(rawComment, 0, rawComment.Length);
				updateFile.SetLength(updateFile.Position);
			}

			if ( archiveStorage_.UpdateMode == FileUpdateMode.Safe ) {
				Reopen(archiveStorage_.ConvertTemporaryToFinal());
			}
			else {
				ReadEntries();
			}
		}
开发者ID:jamesbascle,项目名称:SharpZipLib,代码行数:58,代码来源:ZipFile.cs


示例8: CommitUpdate

		/// <summary>
		/// Commit current updates, updating this archive.
		/// </summary>
		/// <seealso cref="BeginUpdate()"></seealso>
		/// <seealso cref="AbortUpdate"></seealso>
		/// <exception cref="ObjectDisposedException">ZipFile has been closed.</exception>
		public void CommitUpdate()
		{
			if ( isDisposed_ ) {
				throw new ObjectDisposedException("ZipFile");
			}
			
			CheckUpdating();

			try {
				updateIndex_.Clear();
				updateIndex_=null;

				if( contentsEdited_ ) {
					RunUpdates();
				}
				else if( commentEdited_ ) {
					UpdateCommentOnly();
				}
				else {
					// Create an empty archive if none existed originally.
					if( entries_.Length==0 ) {
						byte[] theComment=(newComment_!=null)?newComment_.RawComment:ZipConstants.ConvertToArray(comment_);
						using( ZipHelperStream zhs=new ZipHelperStream(baseStream_) ) {
							zhs.WriteEndOfCentralDirectory(0, 0, 0, theComment);
						}
					}
				}

			}
			finally {
				PostUpdateCleanup();
			}
		}
开发者ID:jamesbascle,项目名称:SharpZipLib,代码行数:39,代码来源:ZipFile.cs


示例9: SetData

		/// <summary>
		/// Set the data from the raw values provided.
		/// </summary>
		/// <param name="data">The raw data to extract values from.</param>
		/// <param name="index">The index to start extracting values from.</param>
		/// <param name="count">The number of bytes available.</param>
		public void SetData(byte[] data, int index, int count)
		{
			using (MemoryStream ms = new MemoryStream(data, index, count, false)) 
			using (ZipHelperStream helperStream = new ZipHelperStream(ms))
			{
				helperStream.ReadLEInt(); // Reserved
				while (helperStream.Position < helperStream.Length)
				{
					int ntfsTag = helperStream.ReadLEShort();
					int ntfsLength = helperStream.ReadLEShort();
					if (ntfsTag == 1)
					{
						if (ntfsLength >= 24)
						{
							long lastModificationTicks = helperStream.ReadLELong();
							lastModificationTime_ = DateTime.FromFileTime(lastModificationTicks);

							long lastAccessTicks = helperStream.ReadLELong();
							lastAccessTime_ = DateTime.FromFileTime(lastAccessTicks);

							long createTimeTicks = helperStream.ReadLELong();
							createTime_ = DateTime.FromFileTime(createTimeTicks);
						}
						break;
					}
					else
					{
						// An unknown NTFS tag so simply skip it.
						helperStream.Seek(ntfsLength, SeekOrigin.Current);
					}
				}
			}
		}
开发者ID:nagyist,项目名称:SparkleDotNET,代码行数:39,代码来源:ZipExtraData.cs


示例10: LocateBlockWithSignature

 private long LocateBlockWithSignature(int signature, long endLocation, int minimumBlockSize, int maximumVariableData)
 {
     using (ZipHelperStream stream = new ZipHelperStream(this.baseStream_))
     {
         return stream.LocateBlockWithSignature(signature, endLocation, minimumBlockSize, maximumVariableData);
     }
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:7,代码来源:ZipFile.cs


示例11: CommitUpdate

 public void CommitUpdate()
 {
     if (this.isDisposed_)
     {
         throw new ObjectDisposedException("ZipFile");
     }
     this.CheckUpdating();
     try
     {
         this.updateIndex_.Clear();
         this.updateIndex_ = null;
         if (this.contentsEdited_)
         {
             this.RunUpdates();
         }
         else if (this.commentEdited_)
         {
             this.UpdateCommentOnly();
         }
         else if (this.entries_.Length == 0)
         {
             byte[] comment = (this.newComment_ != null) ? this.newComment_.RawComment : ZipConstants.ConvertToArray(this.comment_);
             using (ZipHelperStream stream = new ZipHelperStream(this.baseStream_))
             {
                 stream.WriteEndOfCentralDirectory(0L, 0L, 0L, comment);
             }
         }
     }
     finally
     {
         this.PostUpdateCleanup();
     }
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:33,代码来源:ZipFile.cs


示例12: UpdateCommentOnly

 private void UpdateCommentOnly()
 {
     long length = this.baseStream_.Length;
     ZipHelperStream stream = null;
     if (this.archiveStorage_.UpdateMode == FileUpdateMode.Safe)
     {
         stream = new ZipHelperStream(this.archiveStorage_.MakeTemporaryCopy(this.baseStream_)) {
             IsStreamOwner = true
         };
         this.baseStream_.Close();
         this.baseStream_ = null;
     }
     else if (this.archiveStorage_.UpdateMode == FileUpdateMode.Direct)
     {
         this.baseStream_ = this.archiveStorage_.OpenForDirectUpdate(this.baseStream_);
         stream = new ZipHelperStream(this.baseStream_);
     }
     else
     {
         this.baseStream_.Close();
         this.baseStream_ = null;
         stream = new ZipHelperStream(this.Name);
     }
     using (stream)
     {
         if (stream.LocateBlockWithSignature(0x6054b50, length, 0x16, 0xffff) < 0L)
         {
             throw new ZipException("Cannot find central directory");
         }
         stream.Position += 0x10L;
         byte[] rawComment = this.newComment_.RawComment;
         stream.WriteLEShort(rawComment.Length);
         stream.Write(rawComment, 0, rawComment.Length);
         stream.SetLength(stream.Position);
     }
     if (this.archiveStorage_.UpdateMode == FileUpdateMode.Safe)
     {
         this.Reopen(this.archiveStorage_.ConvertTemporaryToFinal());
     }
     else
     {
         this.ReadEntries();
     }
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:44,代码来源:ZipFile.cs


示例13: TestArchive

 public bool TestArchive(bool testData, TestStrategy strategy, ZipTestResultHandler resultHandler)
 {
     if (this.isDisposed_)
     {
         throw new ObjectDisposedException("ZipFile");
     }
     TestStatus status = new TestStatus(this);
     if (resultHandler != null)
     {
         resultHandler(status, null);
     }
     HeaderTest tests = testData ? (HeaderTest.Header | HeaderTest.Extract) : HeaderTest.Header;
     bool flag = true;
     try
     {
         for (int i = 0; flag && (i < this.Count); i++)
         {
             if (resultHandler != null)
             {
                 status.SetEntry(this[i]);
                 status.SetOperation(TestOperation.EntryHeader);
                 resultHandler(status, null);
             }
             try
             {
                 this.TestLocalHeader(this[i], tests);
             }
             catch (ZipException exception)
             {
                 status.AddError();
                 if (resultHandler != null)
                 {
                     resultHandler(status, string.Format("Exception during test - '{0}'", exception.Message));
                 }
                 if (strategy == TestStrategy.FindFirstError)
                 {
                     flag = false;
                 }
             }
             if ((flag && testData) && this[i].IsFile)
             {
                 if (resultHandler != null)
                 {
                     status.SetOperation(TestOperation.EntryData);
                     resultHandler(status, null);
                 }
                 Crc32 crc = new Crc32();
                 using (Stream stream = this.GetInputStream(this[i]))
                 {
                     int num3;
                     byte[] buffer = new byte[0x1000];
                     long num2 = 0L;
                     while ((num3 = stream.Read(buffer, 0, buffer.Length)) > 0)
                     {
                         crc.Update(buffer, 0, num3);
                         if (resultHandler != null)
                         {
                             num2 += num3;
                             status.SetBytesTested(num2);
                             resultHandler(status, null);
                         }
                     }
                 }
                 if (this[i].Crc != crc.Value)
                 {
                     status.AddError();
                     if (resultHandler != null)
                     {
                         resultHandler(status, "CRC mismatch");
                     }
                     if (strategy == TestStrategy.FindFirstError)
                     {
                         flag = false;
                     }
                 }
                 if ((this[i].Flags & 8) != 0)
                 {
                     ZipHelperStream stream2 = new ZipHelperStream(this.baseStream_);
                     DescriptorData data = new DescriptorData();
                     stream2.ReadDataDescriptor(this[i].LocalHeaderRequiresZip64, data);
                     if (this[i].Crc != data.Crc)
                     {
                         status.AddError();
                     }
                     if (this[i].CompressedSize != data.CompressedSize)
                     {
                         status.AddError();
                     }
                     if (this[i].Size != data.Size)
                     {
                         status.AddError();
                     }
                 }
             }
             if (resultHandler != null)
             {
                 status.SetOperation(TestOperation.EntryComplete);
                 resultHandler(status, null);
             }
         }
//.........这里部分代码省略.........
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:101,代码来源:ZipFile.cs


示例14: RunUpdates

 private void RunUpdates()
 {
     ZipFile file;
     long sizeEntries = 0L;
     long num2 = 0L;
     bool flag = false;
     long destinationPosition = 0L;
     if (this.IsNewArchive)
     {
         file = this;
         file.baseStream_.Position = 0L;
         flag = true;
     }
     else if (this.archiveStorage_.UpdateMode == FileUpdateMode.Direct)
     {
         file = this;
         file.baseStream_.Position = 0L;
         flag = true;
         this.updates_.Sort(new UpdateComparer());
     }
     else
     {
         file = Create(this.archiveStorage_.GetTemporaryOutput());
         file.UseZip64 = this.UseZip64;
         if (this.key != null)
         {
             file.key = (byte[]) this.key.Clone();
         }
     }
     try
     {
         foreach (ZipUpdate update in this.updates_)
         {
             if (update != null)
             {
                 switch (update.Command)
                 {
                     case UpdateCommand.Copy:
                     {
                         if (!flag)
                         {
                             goto Label_00EC;
                         }
                         this.CopyEntryDirect(file, update, ref destinationPosition);
                         continue;
                     }
                     case UpdateCommand.Modify:
                     {
                         this.ModifyEntry(file, update);
                         continue;
                     }
                     case UpdateCommand.Add:
                         goto Label_0104;
                 }
             }
             continue;
         Label_00EC:
             this.CopyEntry(file, update);
             continue;
         Label_0104:
             if (!this.IsNewArchive && flag)
             {
                 file.baseStream_.Position = destinationPosition;
             }
             this.AddEntry(file, update);
             if (flag)
             {
                 destinationPosition = file.baseStream_.Position;
             }
         }
         if (!this.IsNewArchive && flag)
         {
             file.baseStream_.Position = destinationPosition;
         }
         long position = file.baseStream_.Position;
         foreach (ZipUpdate update2 in this.updates_)
         {
             if (update2 != null)
             {
                 sizeEntries += file.WriteCentralDirectoryHeader(update2.OutEntry);
             }
         }
         byte[] comment = (this.newComment_ != null) ? this.newComment_.RawComment : ZipConstants.ConvertToArray(this.comment_);
         using (ZipHelperStream stream = new ZipHelperStream(file.baseStream_))
         {
             stream.WriteEndOfCentralDirectory(this.updateCount_, sizeEntries, position, comment);
         }
         num2 = file.baseStream_.Position;
         foreach (ZipUpdate update3 in this.updates_)
         {
             if (update3 != null)
             {
                 if ((update3.CrcPatchOffset > 0L) && (update3.OutEntry.CompressedSize > 0L))
                 {
                     file.baseStream_.Position = update3.CrcPatchOffset;
                     file.WriteLEInt((int) update3.OutEntry.Crc);
                 }
                 if (update3.SizePatchOffset > 0L)
                 {
                     file.baseStream_.Position = update3.SizePatchOffset;
//.........这里部分代码省略.........
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:101,代码来源:ZipFile.cs


示例15: RunUpdates

        void RunUpdates()
        {
            long sizeEntries = 0;
            long endOfStream = 0;
            bool allOk = true;
            bool directUpdate = false;
            long destinationPosition = 0;

            ZipFile workFile;

            if ( IsNewArchive ) {
                workFile = this;
                workFile.baseStream_.Position = 0;
                directUpdate = true;
            }
            else if ( archiveStorage_.UpdateMode == FileUpdateMode.Direct ) {
                workFile = this;
                workFile.baseStream_.Position = 0;
                directUpdate = true;

                updates_.Sort(new UpdateComparer());
            }
            else {
                workFile = ZipFile.Create(archiveStorage_.GetTemporaryOutput());
                workFile.UseZip64 = UseZip64;

                if (key != null) {
                    workFile.key = (byte[])key.Clone();
                }
            }

            try {
                foreach ( ZipUpdate update in updates_ ) {
                    if (update != null) {
                        switch (update.Command) {
                            case UpdateCommand.Copy:
                                if (directUpdate) {
                                    CopyEntryDirect(workFile, update, ref destinationPosition);
                                }
                                else {
                                    CopyEntry(workFile, update);
                                }
                                break;

                            case UpdateCommand.Modify:
                                ModifyEntry(workFile, update);
                                break;

                            case UpdateCommand.Add:
                                if (!IsNewArchive && directUpdate) {
                                    workFile.baseStream_.Position = destinationPosition;
                                }

                                AddEntry(workFile, update);

                                if (directUpdate) {
                                    destinationPosition = workFile.baseStream_.Position;
                                }
                                break;
                        }
                    }
                }

                if ( !IsNewArchive && directUpdate ) {
                    workFile.baseStream_.Position = destinationPosition;
                }

                long centralDirOffset = workFile.baseStream_.Position;

                foreach ( ZipUpdate update in updates_ ) {
                    if (update != null) {
                        sizeEntries += workFile.WriteCentralDirectoryHeader(update.OutEntry);
                    }
                }

                byte[] theComment = (newComment_ != null) ? newComment_.RawComment : ZipConstants.ConvertToArray(comment_);
                using ( ZipHelperStream zhs = new ZipHelperStream(workFile.baseStream_) ) {
                    zhs.WriteEndOfCentralDirectory(updateCount_, sizeEntries, centralDirOffset, theComment);
                }

                endOfStream = workFile.baseStream_.Position;

                foreach ( ZipUpdate update in updates_ ) {
                    if (update != null)
                    {
                        if ((update.CrcPatchOffset > 0) && (update.OutEntry.CompressedSize > 0)) {
                            workFile.baseStream_.Position = update.CrcPatchOffset;
                            workFile.WriteLEInt((int)update.OutEntry.Crc);
                        }

                        if (update.SizePatchOffset > 0) {
                            workFile.baseStream_.Position = update.SizePatchOffset;
                            if (update.OutEntry.LocalHeaderRequiresZip64) {
                                workFile.WriteLeLong(update.OutEntry.Size);
                                workFile.WriteLeLong(update.OutEntry.CompressedSize);
                            }
                            else {
                                workFile.WriteLEInt((int)update.OutEntry.CompressedSize);
                                workFile.WriteLEInt((int)update.OutEntry.Size);
                            }
//.........这里部分代码省略.........
开发者ID:NoobSkie,项目名称:taobao-shop-helper,代码行数:101,代码来源:ZipFile.cs


示例16: UpdateCommentOnly

        void UpdateCommentOnly()
        {
            long baseLength = baseStream_.Length;

            ZipHelperStream updateFile = null;

            if ( archiveStorage_.UpdateMode == FileUpdateMode.Safe ) {
                Stream copyStream = archiveStorage_.MakeTemporaryCopy(baseStream_);
                updateFile = new ZipHelperStream(copyStream);
                updateFile.IsStreamOwner = true;

                baseStream_.Close();
                baseStream_ = null;
            }
            else {
                if (archiveStorage_.UpdateMode == FileUpdateMode.Direct) {

                    baseStream_ = archiveStorage_.OpenForDirectUpdate(baseStream_);
                    updateFile = new ZipHelperStream(baseStream_);
                }
                else {
                    baseStream_.Close();
                    baseStream_ = null;
                    updateFile = new ZipHelperStream(Name);
                }
            }

            using ( updateFile ) {
                long locatedCentralDirOffset =
                    updateFile.LocateBlockWithSignature(ZipConstants.EndOfCentralDirectorySignature,
                                                        baseLength, ZipConstants.EndOfCentralRecordBaseSize, 0xffff);
                if ( locatedCentralDirOffset < 0 ) {
                    throw new ZipException("Cannot find central directory");
                }

                const int CentralHeaderCommentSizeOffset = 16;
                updateFile.Position += CentralHeaderCommentSizeOffset;

                byte[] rawComment = newComment_.RawComment;

                updateFile.WriteLEShort(rawComment.Length);
                updateFile.Write(rawComment, 0, rawComment.Length);
                updateFile.SetLength(updateFile.Position);
            }

            if ( archiveStorage_.UpdateMode == FileUpdateMode.Safe ) {
                Reopen(archiveStorage_.ConvertTemporaryToFinal());
            }
            else {
                ReadEntries();
            }
        }
开发者ID:NoobSkie,项目名称:taobao-shop-helper,代码行数:52,代码来源:ZipFile.cs


示例17: GetData

		/// <summary>
		/// Get the binary data representing this instance.
		/// </summary>
		/// <returns>The raw binary data representing this instance.</returns>
		public byte[] GetData()
		{
			using (MemoryStream ms = new MemoryStream())
			using (ZipHelperStream helperStream = new ZipHelperStream(ms))
			{
				helperStream.IsStreamOwner = false;
				helperStream.WriteByte((byte)flags_);     // Flags
				if ( (flags_ & Flags.ModificationTime) != 0) {
					TimeSpan span = modificationTime_.ToUniversalTime() - new System.DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime();
					int seconds = (int)span.TotalSeconds;
					helperStream.WriteLEInt(seconds);
				}
				if ( (flags_ & Flags.AccessTime) != 0) {
					TimeSpan span = lastAccessTime_.ToUniversalTime() - new System.DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime();
					int seconds = (int)span.TotalSeconds;
					helperStream.WriteLEInt(seconds);
				}
				if ( (flags_ & Flags.CreateTime) != 0) {
					TimeSpan span = createTime_.ToUniversalTime() - new System.DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime();
					int seconds = (int)span.TotalSeconds;
					helperStream.WriteLEInt(seconds);
				}
				return ms.ToArray();
			}
		}
开发者ID:nagyist,项目名称:SparkleDotNET,代码行数:29,代码来源:ZipExtraData.cs


示例18: CommitUpdate

        /// <summary>
        /// Commit current updates, updating this archive.
        /// </summary>
        /// <seealso cref="BeginUpdate()"></seealso>
        /// <seealso cref="AbortUpdate"></seealso>
        public void CommitUpdate()
        {
            CheckUpdating();

            if ( contentsEdited_ ) {
                RunUpdates();
            }
            else if ( commentEdited_ ) {
                UpdateCommentOnly();
            }
            else {
                // Create an empty archive if none existed originally.
                if ( (entries_ != null) && (entries_.Length == 0) ) {
                    byte[] theComment = (newComment_ != null) ? newComment_.RawComment : ZipConstants.ConvertToArray(comment_);
                    using ( ZipHelperStream zhs = new ZipHelperStream(baseStream_) ) {
                        zhs.WriteEndOfCentralDirectory(0, 0, 0, theComment);
                    }
                }
            }

            PostUpdateCleanup();
        }
开发者ID:hirous,项目名称:test,代码行数:27,代码来源:ZipFile.cs


示例19: GetData

 /// <summary>
 /// Get the binary data representing this instance.
 /// </summary>
 /// <returns>The raw binary data representing this instance.</returns>
 public byte[] GetData() {
     using (var ms=new MemoryStream())
     using (var helperStream=new ZipHelperStream(ms)) {
         helperStream.IsStreamOwner=false;
         helperStream.WriteByte((byte)_flags); // Flags
         if ((_flags&Flags.ModificationTime)!=0) {
             TimeSpan span=_modificationTime.ToUniversalTime()-
                             new DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime();
             var seconds=(int)span.TotalSeconds;
             helperStream.WriteLEInt(seconds);
         }
         if ((_flags&Flags.AccessTime)!=0) {
             TimeSpan span=_lastAccessTime.ToUniversalTime()-
                             new DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime();
             var seconds=(int)span.TotalSeconds;
             helperStream.WriteLEInt(seconds);
         }
         if ((_flags&Flags.CreateTime)!=0) {
             TimeSpan span=_createTime.ToUniversalTime()-new DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime();
             var seconds=(int)span.TotalSeconds;
             helperStream.WriteLEInt(seconds);
         }
         return ms.ToArray();
     }
 }
开发者ID:fanfeilong,项目名称:exceltk,代码行数:29,代码来源:ZipExtraData.cs


示例20: AddEntry

		void AddEntry(ZipFile workFile, ZipUpdate update)
		{
			Stream source = null;

			if ( update.Entry.IsFile ) {
				source = update.GetSource();
				
				if ( source == null ) {
					source = updateDataSource_.GetSource(update.Entry, update.Filename);
				}
			}

			if ( source != null ) {
				using ( source ) {
					long sourceStreamLength = source.Length;
					if ( update.OutEntry.Size < 0 ) {
						update.OutEntry.Size = sourceStreamLength;
					}
					else {
						// Check for errant entries.
						if ( update.OutEntry.Size != sourceStreamLength ) {
							throw new ZipException("Entry size/stream size mismatch");
						}
					}

					workFile.WriteLocalEntryHeader(update);

					long dataStart = workFile.baseStream_.Position;

					using ( Stream output = workFile.GetOutputStream(update.OutEntry) ) {
						CopyBytes(update, output, source, sourceStreamLength, true);
					}

					long dataEnd = workFile.baseStream_.Position;
					update.OutEntry.CompressedSize = dataEnd - dataStart;

					if ((update.OutEntry.Flags & (int)GeneralBitFlags.Descriptor) == (int)GeneralBitFlags.Descriptor)
					{
						ZipHelperStream helper = new ZipHelperStream(workFile.baseStream_);
						helper.WriteDataDescriptor(update.OutEntry);
					}
				}
			}
			else {
				workFile.WriteLocalEntryHeader(update);
				update.OutEntry.CompressedSize = 0;
			}

		}
开发者ID:jamesbascle,项目名称:SharpZipLib,代码行数:49,代码来源:ZipFile.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Zip.ZipInputStream类代码示例发布时间:2022-05-26
下一篇:
C# Zip.ZipFile类代码示例发布时间: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