protected override void Dispose(bool disposing) { if (disposing) { _tarStream.Dispose(); } }
public void InputStreamOwnership() { var memStream = new TrackedMemoryStream(); var s = new TarInputStream(memStream); Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially"); Assert.IsFalse(memStream.IsDisposed, "Shouldnt be disposed initially"); #if NET451 s.Close(); #elif NETCOREAPP1_0 s.Dispose(); #endif Assert.IsTrue(memStream.IsClosed, "Should be closed after parent owner close"); Assert.IsTrue(memStream.IsDisposed, "Should be disposed after parent owner close"); memStream = new TrackedMemoryStream(); s = new TarInputStream(memStream); Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially"); Assert.IsFalse(memStream.IsDisposed, "Shouldnt be disposed initially"); s.IsStreamOwner = false; #if NET451 s.Close(); #elif NETCOREAPP1_0 s.Dispose(); #endif Assert.IsFalse(memStream.IsClosed, "Should not be closed after parent owner close"); Assert.IsFalse(memStream.IsDisposed, "Should not be disposed after parent owner close"); }
/// <summary> /// Extracts an a Tar archive /// </summary> /// <param name="fileEntry"> </param> /// <returns> </returns> public async IAsyncEnumerable <FileEntry> ExtractAsync(FileEntry fileEntry, ExtractorOptions options, ResourceGovernor governor) { TarEntry tarEntry; TarInputStream?tarStream = null; try { tarStream = new TarInputStream(fileEntry.Content); } catch (Exception e) { Logger.Debug(Extractor.DEBUG_STRING, ArchiveFileType.TAR, fileEntry.FullPath, string.Empty, e.GetType()); } if (tarStream != null) { while ((tarEntry = tarStream.GetNextEntry()) != null) { if (tarEntry.IsDirectory) { continue; } var fs = new FileStream(Path.GetTempFileName(), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite, 4096, FileOptions.DeleteOnClose); governor.CheckResourceGovernor(tarStream.Length); try { tarStream.CopyEntryContents(fs); } catch (Exception e) { Logger.Debug(Extractor.DEBUG_STRING, ArchiveFileType.TAR, fileEntry.FullPath, tarEntry.Name, e.GetType()); } var name = tarEntry.Name.Replace('/', Path.DirectorySeparatorChar); var newFileEntry = new FileEntry(name, fs, fileEntry, true); if (Extractor.IsQuine(newFileEntry)) { Logger.Info(Extractor.IS_QUINE_STRING, fileEntry.Name, fileEntry.FullPath); throw new OverflowException(); } await foreach (var extractedFile in Context.ExtractAsync(newFileEntry, options, governor)) { yield return(extractedFile); } } tarStream.Dispose(); } else { if (options.ExtractSelfOnFail) { yield return(fileEntry); } } }
protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) { if (!disposed) { tarStream?.Dispose(); compressionStream?.Dispose(); disposed = true; } } }
protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) { if (!disposed) { if (tarStream != null) { tarStream.Dispose(); } disposed = true; } } }
public Task <Stream> ExtractFileAsync(string layerFile, string path) { path = path.TrimStart('/'); // can't put in using block as we're (hopefully) returning all these items nested in the final SubStream var stream = new FileStream(layerFile, FileMode.Open, FileAccess.Read, FileShare.Read); var gzipStream = new GZipInputStream(stream); var tarStream = new TarInputStream(gzipStream); try { Stream foundStream = null; var entry = tarStream.GetNextEntry(); while (entry != null) { if (entry.Name.Equals(path)) { foundStream = new SubStream(tarStream, entry.Size) { OwnInnerStream = true }; break; } entry = tarStream.GetNextEntry(); } if (foundStream != null) { return(Task.FromResult(foundStream)); } else { // tarStream will dispose the entire chain for us tarStream.Dispose(); throw new FileNotFoundException(); } } catch (GZipException) { throw new ArgumentException($"Layer appears invalid"); } }
public void Dispose() { GC.SuppressFinalize(this); dataStream.Dispose(); }