/// <summary> /// Reads all entries using callback functions to acquire and close per entry target streams. /// </summary> /// <param name="streamForEntry">Callback for aquiring a target stream for the specified entry.</param> /// <param name="complete">Callback after stream was written and may be closed.</param> /// <param name="callback">The callback used during stream copy.</param> /// <param name="userItem">A user item for the callback.</param> /// <returns>Returns true if the operation completed, false if the callback used <see cref="ProgressEventArgs.Break"/>.</returns> public bool ReadAll(GetStreamForEntry streamForEntry, Completed complete, ProgressCallback callback = null, object userItem = null) { if (tarStream == null) { throw new ObjectDisposedException(nameof(TarReader)); } var result = true; void CallbackOverride(object s, ProgressEventArgs e) { callback?.Invoke(s, e); if (e.Break) { result = false; } } while (ReadNext(streamForEntry, complete, CallbackOverride, userItem)) { } return(result); }
/// <summary> /// Reads the next file using callback functions to acquire and close per entry target streams. /// </summary> /// <param name="streamForEntry">Callback for aquiring a target stream for the specified entry.</param> /// <param name="complete">Callback after stream was written and may be closed.</param> /// <param name="callback">The callback used during stream copy.</param> /// <param name="userItem">A user item for the callback.</param> /// <returns>Returns true if the operation completed, false if the callback used <see cref="ProgressEventArgs.Break"/>.</returns> public bool ReadNext(GetStreamForEntry streamForEntry, Completed complete, ProgressCallback callback = null, object userItem = null) { if (tarStream == null) { throw new ObjectDisposedException(nameof(TarReader)); } TarEntry tarEntry; while ((tarEntry = tarStream.GetNextEntry()) != null) { if (tarEntry.IsDirectory) { continue; } var targetStream = streamForEntry(tarEntry); tarStream.CopyEntryContents(targetStream, callback, userItem); complete?.Invoke(tarEntry, targetStream); return(true); } return(false); }