From eb5c5faa99252d5dd35917c7f170f1c4dbd9320a Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Fri, 13 Feb 2026 14:43:56 +0000 Subject: [PATCH] some nullability fixes --- src/SharpCompress/Common/Rar/CryptKey3.cs | 6 +- .../Rar/Headers/ArchiveCryptHeader.Async.cs | 2 - .../Common/Rar/Headers/ArchiveCryptHeader.cs | 2 - .../Common/SevenZip/CCoderInfo.cs | 4 +- .../Common/SevenZip/CFileItem.cs | 4 +- src/SharpCompress/Crypto/BlockTransformer.cs | 2 - src/SharpCompress/Crypto/Crc32Stream.cs | 4 +- .../LazyAsyncReadOnlyCollection.cs | 1 - src/SharpCompress/LazyReadOnlyCollection.cs | 4 +- .../Readers/Ace/MultiVolumeAceReader.cs | 10 +-- .../Readers/Arj/MultiVolumeArjReader.cs | 10 +-- .../Readers/Rar/MultiVolumeRarReader.Async.cs | 8 +- .../Readers/Rar/MultiVolumeRarReader.cs | 10 +-- src/SharpCompress/Writers/AbstractWriter.cs | 6 +- .../Writers/GZip/GZipWriter.Async.cs | 2 +- src/SharpCompress/Writers/GZip/GZipWriter.cs | 4 +- .../Writers/Tar/TarWriter.Async.cs | 7 +- src/SharpCompress/Writers/Tar/TarWriter.cs | 10 +-- src/SharpCompress/Writers/Zip/ZipWriter.cs | 82 +++++++++---------- 19 files changed, 76 insertions(+), 102 deletions(-) diff --git a/src/SharpCompress/Common/Rar/CryptKey3.cs b/src/SharpCompress/Common/Rar/CryptKey3.cs index 9f6c1f7c..52d1412b 100644 --- a/src/SharpCompress/Common/Rar/CryptKey3.cs +++ b/src/SharpCompress/Common/Rar/CryptKey3.cs @@ -1,5 +1,3 @@ -#nullable disable - using System.Diagnostics.CodeAnalysis; using System.Security.Cryptography; using System.Text; @@ -16,9 +14,9 @@ internal class CryptKey3 : ICryptKey { const int AES_128 = 128; - private string _password; + private readonly string _password; - public CryptKey3(string password) => _password = password ?? ""; + public CryptKey3(string? password) => _password = password ?? string.Empty; public ICryptoTransform Transformer(byte[] salt) { diff --git a/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.Async.cs b/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.Async.cs index 031fe6bd..eb34ec71 100644 --- a/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.Async.cs +++ b/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.Async.cs @@ -1,5 +1,3 @@ -#nullable disable - using System.Threading; using System.Threading.Tasks; using SharpCompress.Common.Rar; diff --git a/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.cs b/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.cs index 1f5ab837..bdb107fc 100644 --- a/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.cs @@ -1,5 +1,3 @@ -#nullable disable - using SharpCompress.Common.Rar; using SharpCompress.IO; diff --git a/src/SharpCompress/Common/SevenZip/CCoderInfo.cs b/src/SharpCompress/Common/SevenZip/CCoderInfo.cs index d53c44f0..d735b2cd 100644 --- a/src/SharpCompress/Common/SevenZip/CCoderInfo.cs +++ b/src/SharpCompress/Common/SevenZip/CCoderInfo.cs @@ -1,11 +1,9 @@ -#nullable disable - namespace SharpCompress.Common.SevenZip; internal class CCoderInfo { internal CMethodId _methodId; - internal byte[] _props; + internal byte[] _props = []; internal int _numInStreams; internal int _numOutStreams; } diff --git a/src/SharpCompress/Common/SevenZip/CFileItem.cs b/src/SharpCompress/Common/SevenZip/CFileItem.cs index 254a444f..5305bc5d 100644 --- a/src/SharpCompress/Common/SevenZip/CFileItem.cs +++ b/src/SharpCompress/Common/SevenZip/CFileItem.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; namespace SharpCompress.Common.SevenZip; @@ -10,7 +8,7 @@ internal class CFileItem public uint? Attrib { get; internal set; } public uint? ExtendedAttrib { get; internal set; } public uint? Crc { get; internal set; } - public string Name { get; internal set; } + public string Name { get; internal set; } = string.Empty; public bool HasStream { get; internal set; } public bool IsDir { get; internal set; } diff --git a/src/SharpCompress/Crypto/BlockTransformer.cs b/src/SharpCompress/Crypto/BlockTransformer.cs index ed9ead44..d3196aaa 100644 --- a/src/SharpCompress/Crypto/BlockTransformer.cs +++ b/src/SharpCompress/Crypto/BlockTransformer.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Security.Cryptography; diff --git a/src/SharpCompress/Crypto/Crc32Stream.cs b/src/SharpCompress/Crypto/Crc32Stream.cs index 1cbe8884..4a65587e 100644 --- a/src/SharpCompress/Crypto/Crc32Stream.cs +++ b/src/SharpCompress/Crypto/Crc32Stream.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.IO; @@ -15,7 +13,7 @@ public sealed class Crc32Stream : Stream public const uint DEFAULT_POLYNOMIAL = 0xedb88320u; public const uint DEFAULT_SEED = 0xffffffffu; - private static uint[] _defaultTable; + private static uint[]? _defaultTable; public Crc32Stream(Stream stream) : this(stream, DEFAULT_POLYNOMIAL, DEFAULT_SEED) { } diff --git a/src/SharpCompress/LazyAsyncReadOnlyCollection.cs b/src/SharpCompress/LazyAsyncReadOnlyCollection.cs index 6d152593..88d08fdf 100644 --- a/src/SharpCompress/LazyAsyncReadOnlyCollection.cs +++ b/src/SharpCompress/LazyAsyncReadOnlyCollection.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Collections; using System.Collections.Generic; diff --git a/src/SharpCompress/LazyReadOnlyCollection.cs b/src/SharpCompress/LazyReadOnlyCollection.cs index eee60bc7..2a7e95ff 100644 --- a/src/SharpCompress/LazyReadOnlyCollection.cs +++ b/src/SharpCompress/LazyReadOnlyCollection.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Collections; using System.Collections.Generic; @@ -43,7 +41,7 @@ internal sealed class LazyReadOnlyCollection : ICollection #region IEnumerator Members - object IEnumerator.Current => Current; + object IEnumerator.Current => Current!; public bool MoveNext() { diff --git a/src/SharpCompress/Readers/Ace/MultiVolumeAceReader.cs b/src/SharpCompress/Readers/Ace/MultiVolumeAceReader.cs index 0b000f12..c8abfae9 100644 --- a/src/SharpCompress/Readers/Ace/MultiVolumeAceReader.cs +++ b/src/SharpCompress/Readers/Ace/MultiVolumeAceReader.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Collections; using System.Collections.Generic; @@ -15,7 +13,7 @@ namespace SharpCompress.Readers.Ace; internal class MultiVolumeAceReader : AceReader { private readonly IEnumerator streams; - private Stream tempStream; + private Stream? tempStream; internal MultiVolumeAceReader(IEnumerable streams, ReaderOptions options) : base(options) => this.streams = streams.GetEnumerator(); @@ -54,13 +52,13 @@ internal class MultiVolumeAceReader : AceReader { private readonly MultiVolumeAceReader reader; private readonly IEnumerator nextReadableStreams; - private Stream tempStream; + private Stream? tempStream; private bool isFirst = true; internal MultiVolumeStreamEnumerator( MultiVolumeAceReader r, IEnumerator nextReadableStreams, - Stream tempStream + Stream? tempStream ) { reader = r; @@ -72,7 +70,7 @@ internal class MultiVolumeAceReader : AceReader IEnumerator IEnumerable.GetEnumerator() => this; - public FilePart Current { get; private set; } + public FilePart Current { get; private set; } = null!; public void Dispose() { } diff --git a/src/SharpCompress/Readers/Arj/MultiVolumeArjReader.cs b/src/SharpCompress/Readers/Arj/MultiVolumeArjReader.cs index 547541ef..1eb4a9ea 100644 --- a/src/SharpCompress/Readers/Arj/MultiVolumeArjReader.cs +++ b/src/SharpCompress/Readers/Arj/MultiVolumeArjReader.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Collections; using System.Collections.Generic; @@ -16,7 +14,7 @@ namespace SharpCompress.Readers.Arj; internal class MultiVolumeArjReader : ArjReader { private readonly IEnumerator streams; - private Stream tempStream; + private Stream? tempStream; internal MultiVolumeArjReader(IEnumerable streams, ReaderOptions options) : base(options) => this.streams = streams.GetEnumerator(); @@ -55,13 +53,13 @@ internal class MultiVolumeArjReader : ArjReader { private readonly MultiVolumeArjReader reader; private readonly IEnumerator nextReadableStreams; - private Stream tempStream; + private Stream? tempStream; private bool isFirst = true; internal MultiVolumeStreamEnumerator( MultiVolumeArjReader r, IEnumerator nextReadableStreams, - Stream tempStream + Stream? tempStream ) { reader = r; @@ -73,7 +71,7 @@ internal class MultiVolumeArjReader : ArjReader IEnumerator IEnumerable.GetEnumerator() => this; - public FilePart Current { get; private set; } + public FilePart Current { get; private set; } = null!; public void Dispose() { } diff --git a/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.Async.cs b/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.Async.cs index 1f9d4463..620b28c6 100644 --- a/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.Async.cs +++ b/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.Async.cs @@ -1,5 +1,3 @@ -#nullable disable - using System.Collections; using System.Collections.Generic; using System.IO; @@ -26,13 +24,13 @@ internal partial class MultiVolumeRarReader : RarReader { private readonly MultiVolumeRarReader reader; private readonly IEnumerator nextReadableStreams; - private Stream tempStream; + private Stream? tempStream; private bool isFirst = true; internal MultiVolumeStreamAsyncEnumerator( MultiVolumeRarReader r, IEnumerator nextReadableStreams, - Stream tempStream + Stream? tempStream ) { reader = r; @@ -40,7 +38,7 @@ internal partial class MultiVolumeRarReader : RarReader this.tempStream = tempStream; } - public FilePart Current { get; private set; } + public FilePart Current { get; private set; } = null!; public async ValueTask MoveNextAsync() { diff --git a/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.cs b/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.cs index dd811bc5..5456ff6d 100644 --- a/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.cs +++ b/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.cs @@ -1,5 +1,3 @@ -#nullable disable - using System.Collections; using System.Collections.Generic; using System.IO; @@ -14,7 +12,7 @@ namespace SharpCompress.Readers.Rar; internal partial class MultiVolumeRarReader : RarReader { private readonly IEnumerator streams; - private Stream tempStream; + private Stream? tempStream; internal MultiVolumeRarReader(IEnumerable streams, ReaderOptions options) : base(options) => this.streams = streams.GetEnumerator(); @@ -55,13 +53,13 @@ internal partial class MultiVolumeRarReader : RarReader { private readonly MultiVolumeRarReader reader; private readonly IEnumerator nextReadableStreams; - private Stream tempStream; + private Stream? tempStream; private bool isFirst = true; internal MultiVolumeStreamEnumerator( MultiVolumeRarReader r, IEnumerator nextReadableStreams, - Stream tempStream + Stream? tempStream ) { reader = r; @@ -73,7 +71,7 @@ internal partial class MultiVolumeRarReader : RarReader IEnumerator IEnumerable.GetEnumerator() => this; - public FilePart Current { get; private set; } + public FilePart Current { get; private set; } = null!; public void Dispose() { } diff --git a/src/SharpCompress/Writers/AbstractWriter.cs b/src/SharpCompress/Writers/AbstractWriter.cs index c653d73c..60ddb1b1 100644 --- a/src/SharpCompress/Writers/AbstractWriter.cs +++ b/src/SharpCompress/Writers/AbstractWriter.cs @@ -8,7 +8,6 @@ using SharpCompress.IO; namespace SharpCompress.Writers; -#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. public abstract partial class AbstractWriter(ArchiveType type, IWriterOptions writerOptions) : IWriter, IAsyncWriter @@ -19,8 +18,7 @@ public abstract partial class AbstractWriter(ArchiveType type, IWriterOptions wr protected void InitializeStream(Stream stream) => OutputStream = stream; - protected Stream OutputStream { get; private set; } -#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + protected Stream? OutputStream { get; private set; } public ArchiveType WriterType { get; } = type; @@ -57,7 +55,7 @@ public abstract partial class AbstractWriter(ArchiveType type, IWriterOptions wr { if (isDisposing) { - OutputStream.Dispose(); + OutputStream?.Dispose(); } } diff --git a/src/SharpCompress/Writers/GZip/GZipWriter.Async.cs b/src/SharpCompress/Writers/GZip/GZipWriter.Async.cs index 478373aa..a1aa613a 100644 --- a/src/SharpCompress/Writers/GZip/GZipWriter.Async.cs +++ b/src/SharpCompress/Writers/GZip/GZipWriter.Async.cs @@ -19,7 +19,7 @@ public partial class GZipWriter { throw new ArgumentException("Can only write a single stream to a GZip file."); } - var stream = (GZipStream)OutputStream; + var stream = (GZipStream)OutputStream.NotNull(); stream.FileName = filename; stream.LastModified = modificationTime; var progressStream = WrapWithProgress(source, filename); diff --git a/src/SharpCompress/Writers/GZip/GZipWriter.cs b/src/SharpCompress/Writers/GZip/GZipWriter.cs index 41e2ef1e..eebac616 100644 --- a/src/SharpCompress/Writers/GZip/GZipWriter.cs +++ b/src/SharpCompress/Writers/GZip/GZipWriter.cs @@ -43,7 +43,7 @@ public sealed partial class GZipWriter : AbstractWriter if (isDisposing) { //dispose here to finish the GZip, GZip won't close the underlying stream - OutputStream.Dispose(); + OutputStream.NotNull().Dispose(); } base.Dispose(isDisposing); } @@ -63,7 +63,7 @@ public sealed partial class GZipWriter : AbstractWriter } var progressStream = WrapWithProgress(source, filename); - progressStream.CopyTo(OutputStream, Constants.BufferSize); + progressStream.CopyTo(OutputStream.NotNull(), Constants.BufferSize); _wroteToStream = true; } diff --git a/src/SharpCompress/Writers/Tar/TarWriter.Async.cs b/src/SharpCompress/Writers/Tar/TarWriter.Async.cs index db5e00d4..c3cc7bff 100644 --- a/src/SharpCompress/Writers/Tar/TarWriter.Async.cs +++ b/src/SharpCompress/Writers/Tar/TarWriter.Async.cs @@ -29,7 +29,7 @@ public partial class TarWriter header.Name = normalizedName; header.Size = 0; header.EntryType = EntryType.Directory; - await header.WriteAsync(OutputStream, cancellationToken).ConfigureAwait(false); + await header.WriteAsync(OutputStream.NotNull(), cancellationToken).ConfigureAwait(false); } /// @@ -67,10 +67,10 @@ public partial class TarWriter header.LastModifiedTime = modificationTime ?? TarHeader.EPOCH; header.Name = NormalizeFilename(filename); header.Size = realSize; - await header.WriteAsync(OutputStream, cancellationToken).ConfigureAwait(false); + await header.WriteAsync(OutputStream.NotNull(), cancellationToken).ConfigureAwait(false); var progressStream = WrapWithProgress(source, filename); var written = await progressStream - .TransferToAsync(OutputStream, realSize, cancellationToken) + .TransferToAsync(OutputStream.NotNull(), realSize, cancellationToken) .ConfigureAwait(false); await PadTo512Async(written, cancellationToken).ConfigureAwait(false); } @@ -81,6 +81,7 @@ public partial class TarWriter if (zeros > 0) { await OutputStream + .NotNull() .WriteAsync(new byte[zeros], 0, zeros, cancellationToken) .ConfigureAwait(false); } diff --git a/src/SharpCompress/Writers/Tar/TarWriter.cs b/src/SharpCompress/Writers/Tar/TarWriter.cs index 01a3685f..b9b6c074 100644 --- a/src/SharpCompress/Writers/Tar/TarWriter.cs +++ b/src/SharpCompress/Writers/Tar/TarWriter.cs @@ -98,7 +98,7 @@ public partial class TarWriter : AbstractWriter header.Name = normalizedName; header.Size = 0; header.EntryType = EntryType.Directory; - header.Write(OutputStream); + header.Write(OutputStream.NotNull()); } public void Write(string filename, Stream source, DateTime? modificationTime, long? size) @@ -115,9 +115,9 @@ public partial class TarWriter : AbstractWriter header.LastModifiedTime = modificationTime ?? TarHeader.EPOCH; header.Name = NormalizeFilename(filename); header.Size = realSize; - header.Write(OutputStream); + header.Write(OutputStream.NotNull()); var progressStream = WrapWithProgress(source, filename); - size = progressStream.TransferTo(OutputStream, realSize); + size = progressStream.TransferTo(OutputStream.NotNull(), realSize); PadTo512(size.Value); } @@ -125,7 +125,7 @@ public partial class TarWriter : AbstractWriter { var zeros = unchecked((int)(((size + 511L) & ~511L) - size)); - OutputStream.Write(stackalloc byte[zeros]); + OutputStream.NotNull().Write(stackalloc byte[zeros]); } protected override void Dispose(bool isDisposing) @@ -134,7 +134,7 @@ public partial class TarWriter : AbstractWriter { if (finalizeArchiveOnClose) { - OutputStream.Write(stackalloc byte[1024]); + OutputStream.NotNull().Write(stackalloc byte[1024]); } // Use IFinishable interface for generic finalization if (OutputStream is IFinishable finishable) diff --git a/src/SharpCompress/Writers/Zip/ZipWriter.cs b/src/SharpCompress/Writers/Zip/ZipWriter.cs index 6ab572c2..76d46ee9 100644 --- a/src/SharpCompress/Writers/Zip/ZipWriter.cs +++ b/src/SharpCompress/Writers/Zip/ZipWriter.cs @@ -59,7 +59,7 @@ public partial class ZipWriter : AbstractWriter ulong size = 0; foreach (var entry in entries) { - size += entry.Write(OutputStream); + size += entry.Write(OutputStream.NotNull()); } WriteEndRecord(size); } @@ -208,7 +208,7 @@ public partial class ZipWriter : AbstractWriter ) { // We err on the side of caution until the zip specification clarifies how to support this - if (!OutputStream.CanSeek && useZip64) + if (!OutputStream.NotNull().CanSeek && useZip64) { throw new NotSupportedException( "Zip64 extensions are not supported on non-seekable streams" @@ -222,26 +222,26 @@ public partial class ZipWriter : AbstractWriter Span intBuf = stackalloc byte[4]; BinaryPrimitives.WriteUInt32LittleEndian(intBuf, ZipHeaderFactory.ENTRY_HEADER_BYTES); - OutputStream.Write(intBuf); + OutputStream.NotNull().Write(intBuf); if (explicitZipCompressionInfo == ZipCompressionMethod.Deflate) { - if (OutputStream.CanSeek && useZip64) + if (OutputStream.NotNull().CanSeek && useZip64) { - OutputStream.Write(stackalloc byte[] { 45, 0 }); //smallest allowed version for zip64 + OutputStream.NotNull().Write(stackalloc byte[] { 45, 0 }); //smallest allowed version for zip64 } else { - OutputStream.Write(stackalloc byte[] { 20, 0 }); //older version which is more compatible + OutputStream.NotNull().Write(stackalloc byte[] { 20, 0 }); //older version which is more compatible } } else { - OutputStream.Write(stackalloc byte[] { 63, 0 }); //version says we used PPMd or LZMA + OutputStream.NotNull().Write(stackalloc byte[] { 63, 0 }); //version says we used PPMd or LZMA } var flags = Equals(WriterOptions.ArchiveEncoding.GetEncoding(), Encoding.UTF8) ? HeaderFlags.Efs : 0; - if (!OutputStream.CanSeek) + if (!OutputStream.NotNull().CanSeek) { flags |= HeaderFlags.UsePostDataDescriptor; @@ -252,35 +252,35 @@ public partial class ZipWriter : AbstractWriter } BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)flags); - OutputStream.Write(intBuf.Slice(0, 2)); + OutputStream.NotNull().Write(intBuf.Slice(0, 2)); BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)explicitZipCompressionInfo); - OutputStream.Write(intBuf.Slice(0, 2)); // zipping method + OutputStream.NotNull().Write(intBuf.Slice(0, 2)); // zipping method BinaryPrimitives.WriteUInt32LittleEndian( intBuf, zipWriterEntryOptions.ModificationDateTime.DateTimeToDosTime() ); - OutputStream.Write(intBuf); + OutputStream.NotNull().Write(intBuf); // zipping date and time - OutputStream.Write(stackalloc byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }); + OutputStream.NotNull().Write(stackalloc byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }); // unused CRC, un/compressed size, updated later BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)encodedFilename.Length); - OutputStream.Write(intBuf.Slice(0, 2)); // filename length + OutputStream.NotNull().Write(intBuf.Slice(0, 2)); // filename length var extralength = 0; - if (OutputStream.CanSeek && useZip64) + if (OutputStream.NotNull().CanSeek && useZip64) { extralength = 2 + 2 + 8 + 8; } BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)extralength); - OutputStream.Write(intBuf.Slice(0, 2)); // extra length - OutputStream.Write(encodedFilename, 0, encodedFilename.Length); + OutputStream.NotNull().Write(intBuf.Slice(0, 2)); // extra length + OutputStream.NotNull().Write(encodedFilename, 0, encodedFilename.Length); if (extralength != 0) { - OutputStream.Write(new byte[extralength], 0, extralength); // reserve space for zip64 data + OutputStream.NotNull().Write(new byte[extralength], 0, extralength); // reserve space for zip64 data entry.Zip64HeaderOffset = (ushort)(6 + 2 + 2 + 4 + 12 + 2 + 2 + encodedFilename.Length); } @@ -291,11 +291,11 @@ public partial class ZipWriter : AbstractWriter { Span intBuf = stackalloc byte[4]; BinaryPrimitives.WriteUInt32LittleEndian(intBuf, crc); - OutputStream.Write(intBuf); + OutputStream.NotNull().Write(intBuf); BinaryPrimitives.WriteUInt32LittleEndian(intBuf, compressed); - OutputStream.Write(intBuf); + OutputStream.NotNull().Write(intBuf); BinaryPrimitives.WriteUInt32LittleEndian(intBuf, uncompressed); - OutputStream.Write(intBuf); + OutputStream.NotNull().Write(intBuf); } private void WriteEndRecord(ulong size) @@ -315,57 +315,57 @@ public partial class ZipWriter : AbstractWriter var recordlen = 2 + 2 + 4 + 4 + 8 + 8 + 8 + 8; // Write zip64 end of central directory record - OutputStream.Write(stackalloc byte[] { 80, 75, 6, 6 }); + OutputStream.NotNull().Write(stackalloc byte[] { 80, 75, 6, 6 }); BinaryPrimitives.WriteUInt64LittleEndian(intBuf, (ulong)recordlen); - OutputStream.Write(intBuf); // Size of zip64 end of central directory record + OutputStream.NotNull().Write(intBuf); // Size of zip64 end of central directory record BinaryPrimitives.WriteUInt16LittleEndian(intBuf, 45); - OutputStream.Write(intBuf.Slice(0, 2)); // Made by + OutputStream.NotNull().Write(intBuf.Slice(0, 2)); // Made by BinaryPrimitives.WriteUInt16LittleEndian(intBuf, 45); - OutputStream.Write(intBuf.Slice(0, 2)); // Version needed + OutputStream.NotNull().Write(intBuf.Slice(0, 2)); // Version needed BinaryPrimitives.WriteUInt32LittleEndian(intBuf, 0); - OutputStream.Write(intBuf.Slice(0, 4)); // Disk number - OutputStream.Write(intBuf.Slice(0, 4)); // Central dir disk + OutputStream.NotNull().Write(intBuf.Slice(0, 4)); // Disk number + OutputStream.NotNull().Write(intBuf.Slice(0, 4)); // Central dir disk // TODO: entries.Count is int, so max 2^31 files BinaryPrimitives.WriteUInt64LittleEndian(intBuf, (ulong)entries.Count); - OutputStream.Write(intBuf); // Entries in this disk - OutputStream.Write(intBuf); // Total entries + OutputStream.NotNull().Write(intBuf); // Entries in this disk + OutputStream.NotNull().Write(intBuf); // Total entries BinaryPrimitives.WriteUInt64LittleEndian(intBuf, size); - OutputStream.Write(intBuf); // Central Directory size + OutputStream.NotNull().Write(intBuf); // Central Directory size BinaryPrimitives.WriteUInt64LittleEndian(intBuf, (ulong)streamPosition); - OutputStream.Write(intBuf); // Disk offset + OutputStream.NotNull().Write(intBuf); // Disk offset // Write zip64 end of central directory locator - OutputStream.Write(stackalloc byte[] { 80, 75, 6, 7 }); + OutputStream.NotNull().Write(stackalloc byte[] { 80, 75, 6, 7 }); BinaryPrimitives.WriteUInt32LittleEndian(intBuf, 0); - OutputStream.Write(intBuf.Slice(0, 4)); // Entry disk + OutputStream.NotNull().Write(intBuf.Slice(0, 4)); // Entry disk BinaryPrimitives.WriteUInt64LittleEndian(intBuf, (ulong)streamPosition + size); - OutputStream.Write(intBuf); // Offset to the zip64 central directory + OutputStream.NotNull().Write(intBuf); // Offset to the zip64 central directory BinaryPrimitives.WriteUInt32LittleEndian(intBuf, 1); - OutputStream.Write(intBuf.Slice(0, 4)); // Number of disks + OutputStream.NotNull().Write(intBuf.Slice(0, 4)); // Number of disks streamPosition += 4 + 8 + recordlen + (4 + 4 + 8 + 4); } // Write normal end of central directory record - OutputStream.Write(stackalloc byte[] { 80, 75, 5, 6, 0, 0, 0, 0 }); + OutputStream.NotNull().Write(stackalloc byte[] { 80, 75, 5, 6, 0, 0, 0, 0 }); BinaryPrimitives.WriteUInt16LittleEndian( intBuf, (ushort)(entries.Count < 0xFFFF ? entries.Count : 0xFFFF) ); - OutputStream.Write(intBuf.Slice(0, 2)); - OutputStream.Write(intBuf.Slice(0, 2)); + OutputStream.NotNull().Write(intBuf.Slice(0, 2)); + OutputStream.NotNull().Write(intBuf.Slice(0, 2)); BinaryPrimitives.WriteUInt32LittleEndian(intBuf, sizevalue); - OutputStream.Write(intBuf.Slice(0, 4)); + OutputStream.NotNull().Write(intBuf.Slice(0, 4)); BinaryPrimitives.WriteUInt32LittleEndian(intBuf, streampositionvalue); - OutputStream.Write(intBuf.Slice(0, 4)); + OutputStream.NotNull().Write(intBuf.Slice(0, 4)); var encodedComment = WriterOptions.ArchiveEncoding.Encode(zipComment); BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)encodedComment.Length); - OutputStream.Write(intBuf.Slice(0, 2)); - OutputStream.Write(encodedComment, 0, encodedComment.Length); + OutputStream.NotNull().Write(intBuf.Slice(0, 2)); + OutputStream.NotNull().Write(encodedComment, 0, encodedComment.Length); } #region Nested type: ZipWritingStream