本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipHelperStream类的典型用法代码示例。如果您正苦于以下问题:C# ZipHelperStream类的具体用法?C# ZipHelperStream怎么用?C# ZipHelperStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZipHelperStream类属于ICSharpCode.SharpZipLib.Zip命名空间,在下文中一共展示了ZipHelperStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
}
示例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;
}
示例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();
}
}
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
}
}
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
}
//.........这里部分代码省略.........
示例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;
//.........这里部分代码省略.........
示例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);
}
//.........这里部分代码省略.........