-
Notifications
You must be signed in to change notification settings - Fork 512
Enforce seekable, readable and writable on streams #1297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
3ed94dd
be4b6cd
2bae46e
5d14c96
c9a6859
41432ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,3 +24,4 @@ profiler-snapshots/ | |
| .DS_Store | ||
| *.snupkg | ||
| benchmark-results/ | ||
| /.opencode | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,12 +58,8 @@ public static IRarArchive OpenArchive(FileInfo fileInfo, ReaderOptions? readerOp | |
|
|
||
| public static IRarArchive OpenArchive(Stream stream, ReaderOptions? readerOptions = null) | ||
| { | ||
| stream.NotNull(nameof(stream)); | ||
|
|
||
| if (stream is not { CanSeek: true }) | ||
| { | ||
| throw new ArgumentException("Stream must be seekable", nameof(stream)); | ||
| } | ||
| stream.RequireReadable(); | ||
| stream.RequireSeekable(); | ||
|
|
||
| return new RarArchive( | ||
| new SourceStream(stream, _ => null, readerOptions ?? ReaderOptions.ForExternalStream) | ||
|
|
@@ -91,8 +87,8 @@ public static IRarArchive OpenArchive( | |
| ReaderOptions? readerOptions = null | ||
| ) | ||
| { | ||
| streams.NotNull(nameof(streams)); | ||
| var strms = streams; | ||
| var strms = streams.RequireReadable(); | ||
| strms.RequireSeekable(); | ||
| return new RarArchive( | ||
| new SourceStream( | ||
| strms[0], | ||
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -71,8 +71,8 @@ public static IArchive OpenArchive( | |||||||||||||
| ReaderOptions? readerOptions = null | ||||||||||||||
| ) | ||||||||||||||
| { | ||||||||||||||
| streams.NotNull(nameof(streams)); | ||||||||||||||
| var strms = streams; | ||||||||||||||
| var strms = streams.RequireReadable(); | ||||||||||||||
| strms.RequireSeekable(); | ||||||||||||||
|
||||||||||||||
| strms.RequireSeekable(); | |
| strms.RequireSeekable(); | |
| if (strms.Count == 0) | |
| { | |
| throw new ArgumentException("No streams", nameof(streams)); | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,8 +66,8 @@ public static IWritableArchive<TarWriterOptions> OpenArchive( | |
| ReaderOptions? readerOptions = null | ||
| ) | ||
| { | ||
| streams.NotNull(nameof(streams)); | ||
| var strms = streams; | ||
| var strms = streams.RequireReadable(); | ||
| strms.RequireSeekable(); | ||
| var sourceStream = new SourceStream( | ||
| strms[0], | ||
| i => i < strms.Count ? strms[i] : null, | ||
|
||
|
|
@@ -86,12 +86,8 @@ public static IWritableArchive<TarWriterOptions> OpenArchive( | |
| ReaderOptions? readerOptions = null | ||
| ) | ||
| { | ||
| stream.NotNull(nameof(stream)); | ||
|
|
||
| if (stream is not { CanSeek: true }) | ||
| { | ||
| throw new ArgumentException("Stream must be seekable", nameof(stream)); | ||
| } | ||
| stream.RequireReadable(); | ||
| stream.RequireSeekable(); | ||
|
|
||
| return OpenArchive([stream], readerOptions); | ||
| } | ||
|
|
@@ -102,7 +98,8 @@ public static async ValueTask<IWritableAsyncArchive<TarWriterOptions>> OpenAsync | |
| CancellationToken cancellationToken = default | ||
| ) | ||
| { | ||
| stream.NotNull(nameof(stream)); | ||
| stream.RequireReadable(); | ||
| stream.RequireSeekable(); | ||
| var sourceStream = new SourceStream( | ||
| stream, | ||
|
Comment on lines
99
to
103
|
||
| i => null, | ||
|
|
@@ -158,8 +155,8 @@ public static async ValueTask<IWritableAsyncArchive<TarWriterOptions>> OpenAsync | |
| ) | ||
| { | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
| streams.NotNull(nameof(streams)); | ||
| var strms = streams; | ||
| var strms = streams.RequireReadable(); | ||
| strms.RequireSeekable(); | ||
| var sourceStream = new SourceStream( | ||
| strms[0], | ||
| i => i < strms.Count ? strms[i] : null, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,8 +67,8 @@ public static IWritableArchive<ZipWriterOptions> OpenArchive( | |
| ReaderOptions? readerOptions = null | ||
| ) | ||
| { | ||
| streams.NotNull(nameof(streams)); | ||
| var strms = streams; | ||
| var strms = streams.RequireReadable(); | ||
| strms.RequireSeekable(); | ||
| return new ZipArchive( | ||
| new SourceStream( | ||
| strms[0], | ||
|
||
|
|
@@ -83,12 +83,8 @@ public static IWritableArchive<ZipWriterOptions> OpenArchive( | |
| ReaderOptions? readerOptions = null | ||
| ) | ||
| { | ||
| stream.NotNull(nameof(stream)); | ||
|
|
||
| if (stream is not { CanSeek: true }) | ||
| { | ||
| throw new ArgumentException("Stream must be seekable", nameof(stream)); | ||
| } | ||
| stream.RequireReadable(); | ||
| stream.RequireSeekable(); | ||
|
|
||
| return new ZipArchive( | ||
| new SourceStream(stream, i => null, readerOptions ?? ReaderOptions.ForExternalStream) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OpenArchive(IReadOnlyList<Stream>)indexesstrms[0]without guarding against an empty stream list, which will throw anIndexOutOfRangeException. Add an explicitCount == 0check and throw a more meaningful exception (consistent withArchiveFactory.OpenArchive's "No streams" behavior).