change some construction

This commit is contained in:
Adam Hathcock 2026-02-05 08:30:52 +00:00
parent 7231b7b35c
commit d26db95aff
5 changed files with 14 additions and 22 deletions

View file

@ -12,14 +12,14 @@ internal partial class SharpCompressStream
/// The underlying stream will not be disposed when this stream is disposed.
/// </summary>
public static SharpCompressStream CreateNonDisposing(Stream stream) =>
new(stream, leaveStreamOpen: true, passthrough: true);
new(stream, leaveStreamOpen: true, passthrough: true, bufferSize: null);
public static SharpCompressStream Create(
Stream stream,
int? rewindableBufferSize = null
int? bufferSize = null
)
{
int bufferSize = rewindableBufferSize ?? Constants.RewindableBufferSize;
int rewindableBufferSize = bufferSize ?? Constants.RewindableBufferSize;
// If it's a passthrough SharpCompressStream, unwrap it and create proper seekable wrapper
if (stream is SharpCompressStream sharpCompressStream)
@ -37,7 +37,7 @@ internal partial class SharpCompressStream
};
}
// Non-seekable underlying stream - wrap with rolling buffer
return new SharpCompressStream(underlying, bufferSize) { LeaveStreamOpen = true };
return new SharpCompressStream(underlying, true, false, rewindableBufferSize);
}
// Not passthrough - return as-is
return sharpCompressStream;
@ -60,6 +60,6 @@ internal partial class SharpCompressStream
// For non-seekable streams, create a SharpCompressStream with rolling buffer
// to allow limited backward seeking (required by decompressors that over-read)
return new SharpCompressStream(stream, bufferSize);
return new SharpCompressStream(stream, false,false, bufferSize);
}
}

View file

@ -51,29 +51,21 @@ internal partial class SharpCompressStream : Stream, IStreamStack
_logicalPosition = 0;
}
/// <summary>
/// Creates a SharpCompressStream with a rolling buffer that enables limited backward seeking.
/// </summary>
/// <param name="stream">The underlying stream to wrap.</param>
/// <param name="rollingBufferSize">Size of the rolling buffer in bytes.</param>
public SharpCompressStream(Stream stream, int rollingBufferSize)
: this(stream)
{
if (rollingBufferSize > 0)
{
_ringBuffer = new RingBuffer(rollingBufferSize);
}
}
/// <summary>
/// Private constructor for passthrough mode.
/// </summary>
private SharpCompressStream(Stream stream, bool leaveStreamOpen, bool passthrough)
private SharpCompressStream(Stream stream, bool leaveStreamOpen, bool passthrough, int? bufferSize)
{
this.stream = stream;
LeaveStreamOpen = leaveStreamOpen;
_isPassthrough = passthrough;
_logicalPosition = 0;
if (bufferSize.HasValue && bufferSize.Value > 0)
{
_ringBuffer = new RingBuffer(bufferSize.Value);
}
}
/// <summary>

View file

@ -56,7 +56,7 @@ public static partial class ReaderFactory
var sharpCompressStream = SharpCompressStream.Create(
stream,
options.RewindableBufferSize
bufferSize:options.RewindableBufferSize
);
sharpCompressStream.StartRecording();

View file

@ -36,7 +36,7 @@ public static partial class ReaderFactory
var sharpCompressStream = SharpCompressStream.Create(
stream,
options.RewindableBufferSize
bufferSize:options.RewindableBufferSize
);
sharpCompressStream.StartRecording();

View file

@ -59,7 +59,7 @@ public partial class TarReader : AbstractReader<TarEntry, TarVolume>
options = options ?? new ReaderOptions();
var sharpCompressStream = SharpCompressStream.Create(
stream,
options.RewindableBufferSize
bufferSize:options.RewindableBufferSize
);
long pos = sharpCompressStream.Position;
if (GZipArchive.IsGZipFile(sharpCompressStream))