/// <inheritdoc /> public override Stream OpenEntry(ICompressedArchiveEntry entry) { Stream stream = null; var tarArchiveEntry = _entries.FirstOrDefault(e => e.Name == entry.Name); if (tarArchiveEntry != null) { if (IsReadOnly) { lock (TarArchive) { if (ExtractLocation == null) { ExtractLocation = new TemporaryDirectory(); } } TarArchive.ExtractContents(ExtractLocation.Path); var filePath = Path.Combine(ExtractLocation.Path, tarArchiveEntry.Name); stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); } else { stream = tarArchiveEntry.OpenOutputStream(this); } } return(stream); }
private Stream OpenZipEntry(ICompressedArchiveEntry entry) { var zipFileInfo = entry as ZipFileInfo; var stream = zipFileInfo == null ? null : zipFileInfo.GetStream(FileMode.Open, FileAccess.Read); return(stream); }
/// <inheritdoc /> /// <exception cref="System.ArgumentNullException">Thrown if entry has a null name.</exception> /// <exception cref="System.ArgumentOutOfRangeException">Thrown if the entry's name is too long.</exception> /// <exception cref="System.InvalidOperationException">Thrown if archive was opened in read mode.</exception> protected override bool DeleteEntry(ICompressedArchiveEntry entry) { var deleted = entry is ZipFileInfo; if (deleted) { DeleteFileMethod.Value.Invoke(_zipArchiveObject, new object[] { entry.Name }); } return(deleted); }
private Stream OpenZipEntry(ICompressedArchiveEntry entry) { Stream stream = null; var zipEntry = entry as ZipEntry; if (zipEntry != null) { stream = zipEntry.Entry.Open(); } return(stream); }
/// <inheritdoc /> protected override bool DeleteEntry(ICompressedArchiveEntry entry) { var zipEntry = entry as ZipEntry; var deleted = zipEntry != null; if (deleted) { zipEntry.Entry.Delete(); } return(deleted); }
public override Stream OpenEntry(ICompressedArchiveEntry entry) { Stream stream = null; TestCompressedArchiveEntry testEntry; if (_entries.TryGetValue(entry.Name, out testEntry)) { stream = Stream.Null; } return(stream); }
/// <inheritdoc /> public override Stream OpenEntry(ICompressedArchiveEntry entry) { Stream entryStream = null; var gzipEntry = GetEntry(entry.Name) as GZipMemberEntry; if (gzipEntry != null) { BaseStream.Seek(gzipEntry.Offset, SeekOrigin.Begin); entryStream = OpenStreamForEntry(gzipEntry); } return(entryStream); }
protected override bool DeleteEntry(ICompressedArchiveEntry entry) { VerifyUpdateAccess(); TestCompressedArchiveEntry testEntry; var hasEntry = _entries.TryGetValue(entry.Name, out testEntry); if (hasEntry) { _entries.Remove(testEntry.Name); } return(hasEntry); }
/// <inheritdoc /> protected override bool DeleteEntry(ICompressedArchiveEntry entry) { var zipEntry = entry as ZipArchiveEntry; var deleted = zipEntry != null; if (deleted) { deleted = zipEntry.ZipEntry != null; if (deleted) { ZipFile.BeginUpdate(); ZipFile.Delete(zipEntry.ZipEntry); ZipFile.CommitUpdate(); } } return(deleted); }
/// <inheritdoc /> public override Stream OpenEntry(ICompressedArchiveEntry entry) { Stream stream = null; var zipEntry = ZipFile.GetEntry(entry.Name); switch (Mode) { case CompressedArchiveAccessMode.Read: case CompressedArchiveAccessMode.Update: stream = ZipFile.GetInputStream(zipEntry); break; case CompressedArchiveAccessMode.Create: stream = new OutputDataSource(ZipFile, zipEntry); break; } return(stream); }
/// <inheritdoc /> public abstract Stream OpenEntry(ICompressedArchiveEntry entry);
/// <inheritdoc /> protected override bool DeleteEntry(ICompressedArchiveEntry entry) { throw new NotSupportedException(Resources.Strings.CompressedArchiveAccess_TarDeleteEntryNotSupported); }
/// <summary> /// Wraps an instance of <see cref="ICompressedArchiveEntry"/> with a standardized name. /// </summary> /// <param name="originalEntry">The wrapped entry.</param> /// <param name="locationInArchive">The location within an archive used to make an 'absolute' path for nested archive item access.</param> /// <param name="locationIsInNestedContainer">If <c>true</c>, indicates that the wrapped entry is within a nested archive and that /// <paramref name="locationInArchive"/> should be prepended to the entry's name.</param> public NormalizedCompressedArchiveEntry(ICompressedArchiveEntry originalEntry, string locationInArchive, bool locationIsInNestedContainer) : this(originalEntry.Name, locationInArchive, locationIsInNestedContainer) { Original = originalEntry; }
/// <inheritdoc /> public override Stream OpenEntry(ICompressedArchiveEntry entry) { return(OpenZipEntry(entry)); }
protected override bool DeleteEntry(ICompressedArchiveEntry entry) { return(NestedAchiveAccess.DeleteEntry(entry.Name)); }
/// <inheritdoc /> public override Stream OpenEntry(ICompressedArchiveEntry entry) { return(NestedAchiveAccess.OpenEntry(entry)); }
/// <summary> /// Creates an instance of <see cref="ICompressedArchiveAccess"/> that can be used to access a nested archive. /// </summary> /// <param name="parentArchiveAccess">The parent archive, which contains the nested archive indicated by <paramref name="entry"/>.</param> /// <param name="entry">The entry within <paramref name="parentArchiveAccess"/> that indicates a nested archive.</param> /// <returns>An instance of <see cref="NestedCompressedArchiveAccess"/>, which provides access to the nested archive.</returns> /// <remarks>This wrapper type takes care of cleaning up any temporary files that may be required to access the nested archive. /// For example, some data streams used to access an archive are not navigable from the parent stream (GZIP).</remarks> public static NestedCompressedArchiveAccess Create(ICompressedArchiveAccess parentArchiveAccess, ICompressedArchiveEntry entry) { NestedCompressedArchiveAccess nestedCompressedArchive = null; var entryName = entry.Name; var nestedArchiveFormats = Path.GetExtension(entryName).GetCompressedArchiveFormatsFromFileExtension(); var nestedArchiveFormat = nestedArchiveFormats.FirstOrDefault(); if (nestedArchiveFormat.IsCompressedArchiveFormatSupported()) { TemporaryDirectory temporaryLocation = null; var entryData = parentArchiveAccess.OpenEntry(entry); if (FormatMustBeExtracted(parentArchiveAccess.Format) || FormatMustBeExtracted(nestedArchiveFormat)) { // We can't fully navigate the nested stream, so extract to disk, then proceed. temporaryLocation = new TemporaryDirectory(); var temporaryEntryFilePath = Path.Combine(temporaryLocation.Path, entryName); if (Directory.CreateDirectory(Path.GetDirectoryName(temporaryEntryFilePath)).Exists) { System.Diagnostics.Debug.WriteLine("Extracted entry " + entryName + " to " + temporaryLocation.Path); var fileStream = new FileStream(temporaryEntryFilePath, FileMode.Create, FileAccess.ReadWrite); entryData.CopyTo(fileStream); fileStream.Seek(0, SeekOrigin.Begin); entryData.Dispose(); entryData = fileStream; } } var compressedArchive = CompressedArchiveAccess.Open(entryData, nestedArchiveFormat, CompressedArchiveAccessMode.Read); nestedCompressedArchive = new NestedCompressedArchiveAccess(parentArchiveAccess, compressedArchive, temporaryLocation); nestedCompressedArchive.NestedArchiveFormats = nestedArchiveFormats; } return(nestedCompressedArchive); }
private static ICompressedArchiveEntry MakeAbsoluteEntry(this ICompressedArchiveEntry entry, string location) { ((NormalizedCompressedArchiveEntry)entry).MakeAbsoluteEntryName(location); return(entry); }
/// <summary> /// Deletes an entry from the archive. /// </summary> /// <param name="entry">The entry to remove.</param> /// <returns><c>true</c> if the entry was removed, <c>false</c> otherwise.</returns> protected abstract bool DeleteEntry(ICompressedArchiveEntry entry);