mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Handle as many warnings as possible
This commit is contained in:
@@ -92,16 +92,16 @@ namespace SabreTools.FileTypes.Archives
|
||||
FileStream outstream = File.Create(Path.Combine(outDir, Path.GetFileNameWithoutExtension(this.Filename)));
|
||||
var gz = new gZip();
|
||||
ZipReturn ret = gz.ZipFileOpen(this.Filename);
|
||||
ret = gz.ZipFileOpenReadStream(0, out Stream gzstream, out ulong streamSize);
|
||||
ret = gz.ZipFileOpenReadStream(0, out Stream? gzstream, out ulong streamSize);
|
||||
#if NET20 || NET35
|
||||
byte[] buffer = new byte[32768];
|
||||
int read;
|
||||
while ((read = gzstream.Read(buffer, 0, buffer.Length)) > 0)
|
||||
while ((read = gzstream!.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
outstream.Write(buffer, 0, read);
|
||||
}
|
||||
#else
|
||||
gzstream.CopyTo(outstream);
|
||||
gzstream!.CopyTo(outstream);
|
||||
#endif
|
||||
|
||||
// Dispose of the streams
|
||||
@@ -189,12 +189,12 @@ namespace SabreTools.FileTypes.Archives
|
||||
realEntry = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
var gz = new gZip();
|
||||
ZipReturn ret = gz.ZipFileOpen(this.Filename);
|
||||
ret = gz.ZipFileOpenReadStream(0, out Stream gzstream, out ulong streamSize);
|
||||
ret = gz.ZipFileOpenReadStream(0, out Stream? gzstream, out ulong streamSize);
|
||||
|
||||
// Write the file out
|
||||
byte[] gbuffer = new byte[_bufferSize];
|
||||
int glen;
|
||||
while ((glen = gzstream.Read(gbuffer, 0, _bufferSize)) > 0)
|
||||
while ((glen = gzstream!.Read(gbuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
|
||||
ms.Write(gbuffer, 0, glen);
|
||||
@@ -260,12 +260,12 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
var gz = new gZip();
|
||||
ZipReturn ret = gz.ZipFileOpen(this.Filename);
|
||||
ret = gz.ZipFileOpenReadStream(0, out Stream gzstream, out ulong streamSize);
|
||||
ret = gz.ZipFileOpenReadStream(0, out Stream? gzstream, out ulong streamSize);
|
||||
gzipEntryRom = GetInfo(gzstream, hashes: this.AvailableHashTypes);
|
||||
gzipEntryRom.Filename = gz.GetLocalFile(0).Filename;
|
||||
gzipEntryRom.Parent = gamename;
|
||||
gzipEntryRom.Date = (gz.TimeStamp > 0 ? gz.TimeStamp.ToString() : null);
|
||||
gzstream.Dispose();
|
||||
gzstream!.Dispose();
|
||||
}
|
||||
|
||||
// Fill in comon details and add to the list
|
||||
|
||||
@@ -115,28 +115,28 @@ namespace SabreTools.FileTypes.Archives
|
||||
for (int i = 0; i < zf.LocalFilesCount() && zr == ZipReturn.ZipGood; i++)
|
||||
{
|
||||
// Open the read stream
|
||||
zr = zf.ZipFileOpenReadStream(i, out Stream readStream, out ulong streamsize);
|
||||
zr = zf.ZipFileOpenReadStream(i, out Stream? readStream, out ulong streamsize);
|
||||
|
||||
// Create the rest of the path, if needed
|
||||
if (!string.IsNullOrEmpty(Path.GetDirectoryName(zf.GetLocalFile(i).Filename)))
|
||||
Directory.CreateDirectory(Path.Combine(outDir, Path.GetDirectoryName(zf.GetLocalFile(i).Filename)!));
|
||||
|
||||
// If the entry ends with a directory separator, continue to the next item, if any
|
||||
if (zf.GetLocalFile(i).Filename.EndsWith(Path.DirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename.EndsWith(Path.AltDirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename.EndsWith(Path.PathSeparator.ToString()))
|
||||
if (zf.GetLocalFile(i).Filename!.EndsWith(Path.DirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename!.EndsWith(Path.AltDirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename!.EndsWith(Path.PathSeparator.ToString()))
|
||||
{
|
||||
zf.ZipFileCloseReadStream();
|
||||
continue;
|
||||
}
|
||||
|
||||
FileStream writeStream = File.Create(Path.Combine(outDir, zf.GetLocalFile(i).Filename));
|
||||
FileStream writeStream = File.Create(Path.Combine(outDir, zf.GetLocalFile(i).Filename!));
|
||||
|
||||
// If the stream is smaller than the buffer, just run one loop through to avoid issues
|
||||
if (streamsize < _bufferSize)
|
||||
{
|
||||
byte[] ibuffer = new byte[streamsize];
|
||||
int ilen = readStream.Read(ibuffer, 0, (int)streamsize);
|
||||
int ilen = readStream!.Read(ibuffer, 0, (int)streamsize);
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
@@ -146,7 +146,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
int realBufferSize = (streamsize < _bufferSize ? (int)streamsize : _bufferSize);
|
||||
byte[] ibuffer = new byte[realBufferSize];
|
||||
int ilen;
|
||||
while ((ilen = readStream.Read(ibuffer, 0, realBufferSize)) > 0)
|
||||
while ((ilen = readStream!.Read(ibuffer, 0, realBufferSize)) > 0)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
@@ -241,17 +241,17 @@ namespace SabreTools.FileTypes.Archives
|
||||
|
||||
for (int i = 0; i < zf.LocalFilesCount() && zr == ZipReturn.ZipGood; i++)
|
||||
{
|
||||
if (zf.GetLocalFile(i).Filename.Contains(entryName))
|
||||
if (zf.GetLocalFile(i).Filename!.Contains(entryName))
|
||||
{
|
||||
// Open the read stream
|
||||
realEntry = zf.GetLocalFile(i).Filename;
|
||||
zr = zf.ZipFileOpenReadStream(i, out Stream readStream, out ulong streamsize);
|
||||
zr = zf.ZipFileOpenReadStream(i, out Stream? readStream, out ulong streamsize);
|
||||
|
||||
// If the stream is smaller than the buffer, just run one loop through to avoid issues
|
||||
if (streamsize < _bufferSize)
|
||||
{
|
||||
byte[] ibuffer = new byte[streamsize];
|
||||
int ilen = readStream.Read(ibuffer, 0, (int)streamsize);
|
||||
int ilen = readStream!.Read(ibuffer, 0, (int)streamsize);
|
||||
ms.Write(ibuffer, 0, ilen);
|
||||
ms.Flush();
|
||||
}
|
||||
@@ -262,13 +262,13 @@ namespace SabreTools.FileTypes.Archives
|
||||
int ilen;
|
||||
while (streamsize > _bufferSize)
|
||||
{
|
||||
ilen = readStream.Read(ibuffer, 0, _bufferSize);
|
||||
ilen = readStream!.Read(ibuffer, 0, _bufferSize);
|
||||
ms.Write(ibuffer, 0, ilen);
|
||||
ms.Flush();
|
||||
streamsize -= _bufferSize;
|
||||
}
|
||||
|
||||
ilen = readStream.Read(ibuffer, 0, (int)streamsize);
|
||||
ilen = readStream!.Read(ibuffer, 0, (int)streamsize);
|
||||
ms.Write(ibuffer, 0, ilen);
|
||||
ms.Flush();
|
||||
}
|
||||
@@ -317,15 +317,15 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
// If the entry is a directory (or looks like a directory), we don't want to open it
|
||||
if (zf.GetLocalFile(i).IsDirectory
|
||||
|| zf.GetLocalFile(i).Filename.EndsWith(Path.DirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename.EndsWith(Path.AltDirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename.EndsWith(Path.PathSeparator.ToString()))
|
||||
|| zf.GetLocalFile(i).Filename!.EndsWith(Path.DirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename!.EndsWith(Path.AltDirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename!.EndsWith(Path.PathSeparator.ToString()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Open the read stream
|
||||
zr = zf.ZipFileOpenReadStream(i, out Stream readStream, out ulong streamsize);
|
||||
zr = zf.ZipFileOpenReadStream(i, out Stream? readStream, out ulong streamsize);
|
||||
|
||||
// If we get a read error, log it and continue
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
@@ -390,7 +390,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
List<(string, bool)> zipEntries = [];
|
||||
for (int i = 0; i < zf.LocalFilesCount(); i++)
|
||||
{
|
||||
zipEntries.Add((zf.GetLocalFile(i).Filename, zf.GetLocalFile(i).IsDirectory));
|
||||
zipEntries.Add((zf.GetLocalFile(i).Filename!, zf.GetLocalFile(i).IsDirectory));
|
||||
}
|
||||
|
||||
zipEntries = zipEntries.OrderBy(p => p.Item1, new NaturalReversedComparer()).ToList();
|
||||
@@ -528,7 +528,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
var oldZipFileContents = new List<string>();
|
||||
for (int i = 0; i < oldZipFile.LocalFilesCount(); i++)
|
||||
{
|
||||
oldZipFileContents.Add(oldZipFile.GetLocalFile(i).Filename);
|
||||
oldZipFileContents.Add(oldZipFile.GetLocalFile(i).Filename!);
|
||||
}
|
||||
|
||||
// If the old one doesn't contain the new file, then add it
|
||||
@@ -540,7 +540,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
// Then add all of the old entries to it too
|
||||
for (int i = 0; i < oldZipFile.LocalFilesCount(); i++)
|
||||
{
|
||||
inputIndexMap.Add(oldZipFile.GetLocalFile(i).Filename, i);
|
||||
inputIndexMap.Add(oldZipFile.GetLocalFile(i).Filename!, i);
|
||||
}
|
||||
|
||||
// If the number of entries is the same as the old archive, skip out
|
||||
@@ -600,15 +600,15 @@ namespace SabreTools.FileTypes.Archives
|
||||
else
|
||||
{
|
||||
// Instantiate the streams
|
||||
oldZipFile.ZipFileOpenReadStream(index, out Stream zreadStream, out ulong istreamSize);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.GetLocalFile(index).Filename, istreamSize, 0, out writeStream, null);
|
||||
oldZipFile.ZipFileOpenReadStream(index, out Stream? zreadStream, out ulong istreamSize);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.GetLocalFile(index).Filename!, istreamSize, 0, out writeStream, null);
|
||||
|
||||
// Copy the input stream to the output
|
||||
if (writeStream != null)
|
||||
{
|
||||
byte[] ibuffer = new byte[_bufferSize];
|
||||
int ilen;
|
||||
while ((ilen = zreadStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
while ((ilen = zreadStream!.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
writeStream.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
@@ -616,7 +616,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
oldZipFile.ZipFileCloseReadStream();
|
||||
zipFile.ZipFileCloseWriteStream(oldZipFile.GetLocalFile(index).CRC);
|
||||
zipFile.ZipFileCloseWriteStream(oldZipFile.GetLocalFile(index).CRC!);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -752,7 +752,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
var oldZipFileContents = new List<string>();
|
||||
for (int j = 0; j < oldZipFile.LocalFilesCount(); j++)
|
||||
{
|
||||
oldZipFileContents.Add(oldZipFile.GetLocalFile(j).Filename);
|
||||
oldZipFileContents.Add(oldZipFile.GetLocalFile(j).Filename!);
|
||||
}
|
||||
|
||||
// If the old one contains the new file, then just skip out
|
||||
@@ -767,7 +767,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
// Then add all of the old entries to it too
|
||||
for (int i = 0; i < oldZipFile.LocalFilesCount(); i++)
|
||||
{
|
||||
inputIndexMap.Add(oldZipFile.GetLocalFile(i).Filename, i);
|
||||
inputIndexMap.Add(oldZipFile.GetLocalFile(i).Filename!, i);
|
||||
}
|
||||
|
||||
// If the number of entries is the same as the old archive, skip out
|
||||
@@ -825,19 +825,19 @@ namespace SabreTools.FileTypes.Archives
|
||||
else
|
||||
{
|
||||
// Instantiate the streams
|
||||
oldZipFile.ZipFileOpenReadStream(index, out Stream zreadStream, out ulong istreamSize);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.GetLocalFile(index).Filename, istreamSize, 0, out writeStream, null);
|
||||
oldZipFile.ZipFileOpenReadStream(index, out Stream? zreadStream, out ulong istreamSize);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.GetLocalFile(index).Filename!, istreamSize, 0, out writeStream, null);
|
||||
|
||||
// Copy the input stream to the output
|
||||
byte[] ibuffer = new byte[_bufferSize];
|
||||
int ilen;
|
||||
while ((ilen = zreadStream.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
while ((ilen = zreadStream!.Read(ibuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
writeStream!.Write(ibuffer, 0, ilen);
|
||||
writeStream.Flush();
|
||||
}
|
||||
|
||||
zipFile.ZipFileCloseWriteStream(oldZipFile.GetLocalFile(index).CRC);
|
||||
zipFile.ZipFileCloseWriteStream(oldZipFile.GetLocalFile(index).CRC!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,10 +330,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
oldTarFile = TarArchive.Open(archiveFileName);
|
||||
|
||||
// Get a list of all current entries
|
||||
List<string> entries = oldTarFile.Entries.Select(i => i.Key).ToList();
|
||||
var entries = oldTarFile.Entries.Select(i => i.Key).ToList();
|
||||
|
||||
// Map all inputs to index
|
||||
Dictionary<string, int> inputIndexMap = new();
|
||||
var inputIndexMap = new Dictionary<string, int>();
|
||||
|
||||
// If the old one doesn't contain the new file, then add it
|
||||
if (!entries.Contains(baseFile.Filename.Replace('\\', '/')))
|
||||
@@ -342,7 +342,11 @@ namespace SabreTools.FileTypes.Archives
|
||||
// Then add all of the old entries to it too
|
||||
for (int i = 0; i < entries.Count; i++)
|
||||
{
|
||||
inputIndexMap.Add(entries[i], i);
|
||||
var entry = entries[i];
|
||||
if (entry == null)
|
||||
continue;
|
||||
|
||||
inputIndexMap.Add(entry, i);
|
||||
}
|
||||
|
||||
// If the number of entries is the same as the old archive, skip out
|
||||
@@ -364,7 +368,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
|
||||
// Get temporary date-time if possible
|
||||
DateTime? usableDate = null;
|
||||
if (UseDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out DateTime dt))
|
||||
if (UseDates && !string.IsNullOrEmpty(baseFile.Date) && DateTime.TryParse(baseFile.Date!.Replace('\\', '/'), out DateTime dt))
|
||||
usableDate = dt;
|
||||
|
||||
// If we have the input file, add it now
|
||||
@@ -498,10 +502,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
oldTarFile = TarArchive.Open(archiveFileName);
|
||||
|
||||
// Get a list of all current entries
|
||||
List<string> entries = oldTarFile.Entries.Select(i => i.Key).ToList();
|
||||
var entries = oldTarFile.Entries.Select(i => i.Key).ToList();
|
||||
|
||||
// Map all inputs to index
|
||||
Dictionary<string, int> inputIndexMap = new();
|
||||
var inputIndexMap = new Dictionary<string, int>();
|
||||
for (int i = 0; i < inputFiles.Count; i++)
|
||||
{
|
||||
// If the old one contains the new file, then just skip out
|
||||
@@ -516,7 +520,11 @@ namespace SabreTools.FileTypes.Archives
|
||||
// Then add all of the old entries to it too
|
||||
for (int i = 0; i < entries.Count; i++)
|
||||
{
|
||||
inputIndexMap.Add(entries[i], i);
|
||||
var entry = entries[i];
|
||||
if (entry == null)
|
||||
continue;
|
||||
|
||||
inputIndexMap.Add(entry, i);
|
||||
}
|
||||
|
||||
// If the number of entries is the same as the old archive, skip out
|
||||
|
||||
@@ -268,7 +268,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
// Check for the file existing first
|
||||
if (!File.Exists(this.Filename))
|
||||
if (this.Filename == null || !File.Exists(this.Filename))
|
||||
return false;
|
||||
|
||||
string datum = Path.GetFileName(this.Filename).ToLowerInvariant();
|
||||
@@ -290,7 +290,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
public BaseFile? GetTorrentXZFileInfo()
|
||||
{
|
||||
// Check for the file existing first
|
||||
if (!File.Exists(this.Filename))
|
||||
if (this.Filename == null || !File.Exists(this.Filename))
|
||||
return null;
|
||||
|
||||
string datum = Path.GetFileName(this.Filename).ToLowerInvariant();
|
||||
|
||||
@@ -97,15 +97,15 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
// If the entry ends with a directory separator, continue to the next item, if any
|
||||
if (zf.GetLocalFile(i).Filename.EndsWith(Path.DirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename.EndsWith(Path.AltDirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename.EndsWith(Path.PathSeparator.ToString()))
|
||||
if (zf.GetLocalFile(i).Filename!.EndsWith(Path.DirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename!.EndsWith(Path.AltDirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename!.EndsWith(Path.PathSeparator.ToString()))
|
||||
{
|
||||
zf.ZipFileCloseReadStream();
|
||||
continue;
|
||||
}
|
||||
|
||||
FileStream writeStream = File.Create(Path.Combine(outDir, zf.GetLocalFile(i).Filename));
|
||||
FileStream writeStream = File.Create(Path.Combine(outDir, zf.GetLocalFile(i).Filename!));
|
||||
|
||||
// If the stream is smaller than the buffer, just run one loop through to avoid issues
|
||||
if (streamsize < _bufferSize)
|
||||
@@ -212,7 +212,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
|
||||
for (int i = 0; i < zf.LocalFilesCount() && zr == ZipReturn.ZipGood; i++)
|
||||
{
|
||||
if (zf.GetLocalFile(i).Filename.Contains(entryName))
|
||||
if (zf.GetLocalFile(i).Filename!.Contains(entryName))
|
||||
{
|
||||
// Open the read stream
|
||||
realEntry = zf.GetLocalFile(i).Filename;
|
||||
@@ -283,9 +283,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
// If the entry is a directory (or looks like a directory), we don't want to open it
|
||||
if (zf.GetLocalFile(i).IsDirectory
|
||||
|| zf.GetLocalFile(i).Filename.EndsWith(Path.DirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename.EndsWith(Path.AltDirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename.EndsWith(Path.PathSeparator.ToString()))
|
||||
|| zf.GetLocalFile(i).Filename!.EndsWith(Path.DirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename!.EndsWith(Path.AltDirectorySeparatorChar.ToString())
|
||||
|| zf.GetLocalFile(i).Filename!.EndsWith(Path.PathSeparator.ToString()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -353,7 +353,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
List<(string, bool)> zipEntries = new();
|
||||
for (int i = 0; i < zf.LocalFilesCount(); i++)
|
||||
{
|
||||
zipEntries.Add((zf.GetLocalFile(i).Filename, zf.GetLocalFile(i).IsDirectory));
|
||||
zipEntries.Add((zf.GetLocalFile(i).Filename!, zf.GetLocalFile(i).IsDirectory));
|
||||
}
|
||||
|
||||
zipEntries = zipEntries.OrderBy(p => p.Item1, new NaturalReversedComparer()).ToList();
|
||||
@@ -484,7 +484,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
var oldZipFileContents = new List<string>();
|
||||
for (int i = 0; i < oldZipFile.LocalFilesCount(); i++)
|
||||
{
|
||||
oldZipFileContents.Add(oldZipFile.GetLocalFile(i).Filename);
|
||||
oldZipFileContents.Add(oldZipFile.GetLocalFile(i).Filename!);
|
||||
}
|
||||
|
||||
// If the old one doesn't contain the new file, then add it
|
||||
@@ -494,7 +494,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
// Then add all of the old entries to it too
|
||||
for (int i = 0; i < oldZipFile.LocalFilesCount(); i++)
|
||||
{
|
||||
inputIndexMap.Add(oldZipFile.GetLocalFile(i).Filename, i);
|
||||
inputIndexMap.Add(oldZipFile.GetLocalFile(i).Filename!, i);
|
||||
}
|
||||
|
||||
// If the number of entries is the same as the old archive, skip out
|
||||
@@ -554,7 +554,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
oldZipFile.ZipFileOpenReadStream(index, false, out Stream? zreadStream, out ulong istreamSize, out ushort icompressionMethod);
|
||||
long msDosDateTime = oldZipFile.GetLocalFile(index).LastModified;
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.GetLocalFile(index).Filename, istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.GetLocalFile(index).Filename!, istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
|
||||
|
||||
// Copy the input stream to the output
|
||||
byte[] ibuffer = new byte[_bufferSize];
|
||||
@@ -566,7 +566,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
}
|
||||
|
||||
oldZipFile.ZipFileCloseReadStream();
|
||||
zipFile.ZipFileCloseWriteStream(oldZipFile.GetLocalFile(index).CRC);
|
||||
zipFile.ZipFileCloseWriteStream(oldZipFile.GetLocalFile(index).CRC!);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -704,7 +704,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
var oldZipFileContents = new List<string>();
|
||||
for (int j = 0; j < oldZipFile.LocalFilesCount(); j++)
|
||||
{
|
||||
oldZipFileContents.Add(oldZipFile.GetLocalFile(j).Filename);
|
||||
oldZipFileContents.Add(oldZipFile.GetLocalFile(j).Filename!);
|
||||
}
|
||||
|
||||
// If the old one contains the new file, then just skip out
|
||||
@@ -719,7 +719,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
// Then add all of the old entries to it too
|
||||
for (int i = 0; i < oldZipFile.LocalFilesCount(); i++)
|
||||
{
|
||||
inputIndexMap.Add(oldZipFile.GetLocalFile(i).Filename, i);
|
||||
inputIndexMap.Add(oldZipFile.GetLocalFile(i).Filename!, i);
|
||||
}
|
||||
|
||||
// If the number of entries is the same as the old archive, skip out
|
||||
@@ -780,7 +780,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
oldZipFile.ZipFileOpenReadStream(index, false, out Stream? zreadStream, out ulong istreamSize, out ushort icompressionMethod);
|
||||
long msDosDateTime = oldZipFile.GetLocalFile(index).LastModified;
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.GetLocalFile(index).Filename, istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.GetLocalFile(index).Filename!, istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
|
||||
|
||||
// Copy the input stream to the output
|
||||
byte[] ibuffer = new byte[_bufferSize];
|
||||
@@ -791,7 +791,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
writeStream.Flush();
|
||||
}
|
||||
|
||||
zipFile.ZipFileCloseWriteStream(oldZipFile.GetLocalFile(index).CRC);
|
||||
zipFile.ZipFileCloseWriteStream(oldZipFile.GetLocalFile(index).CRC!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,24 +9,24 @@ namespace Compress
|
||||
|
||||
public static void CreateDirForFile(string sFilename)
|
||||
{
|
||||
string strTemp = Path.GetDirectoryName(sFilename);
|
||||
string? strTemp = Path.GetDirectoryName(sFilename);
|
||||
|
||||
if (string.IsNullOrEmpty(strTemp))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Directory.Exists(strTemp))
|
||||
if (Directory.Exists(strTemp!))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(strTemp);
|
||||
Directory.CreateDirectory(strTemp!);
|
||||
}
|
||||
|
||||
// according to the zip documents, zip filenames are stored as MS-DOS Code Page 437.
|
||||
// (Unless the unicode flag is set, in which case they are stored as UTF-8.
|
||||
private static Encoding enc = null;
|
||||
private static Encoding? enc = null;
|
||||
|
||||
public static void EncodeSetup()
|
||||
{
|
||||
@@ -41,7 +41,7 @@ namespace Compress
|
||||
|
||||
public static string GetString(byte[] byteArr)
|
||||
{
|
||||
return enc.GetString(byteArr);
|
||||
return enc!.GetString(byteArr);
|
||||
}
|
||||
|
||||
// to test if a filename can be stored as codepage 437 we take the filename string
|
||||
@@ -49,7 +49,7 @@ namespace Compress
|
||||
// and we see if we lost characters as a result of the conversion there and back.
|
||||
internal static bool IsCodePage437(string s)
|
||||
{
|
||||
byte[] bOut = enc.GetBytes(s);
|
||||
byte[] bOut = enc!.GetBytes(s);
|
||||
string sOut = enc.GetString(bOut);
|
||||
|
||||
return CompareString(s, sOut);
|
||||
@@ -57,7 +57,7 @@ namespace Compress
|
||||
|
||||
internal static byte[] GetBytes(string s)
|
||||
{
|
||||
return enc.GetBytes(s);
|
||||
return enc!.GetBytes(s);
|
||||
}
|
||||
|
||||
internal static bool CompareString(string s1, string s2)
|
||||
|
||||
@@ -9,9 +9,9 @@ namespace Compress.File
|
||||
{
|
||||
public class File : ICompress
|
||||
{
|
||||
private FileInfo _fileInfo;
|
||||
private Stream _inStream;
|
||||
private byte[] _crc;
|
||||
private FileInfo? _fileInfo;
|
||||
private Stream? _inStream;
|
||||
private byte[]? _crc;
|
||||
|
||||
public string ZipFilename => _fileInfo?.FullName ?? "";
|
||||
|
||||
@@ -32,8 +32,8 @@ namespace Compress.File
|
||||
LocalFile lf = new()
|
||||
{
|
||||
Filename = Path.GetFileName(ZipFilename),
|
||||
UncompressedSize = _fileInfo != null ? (ulong)_fileInfo.Length : (ulong)_inStream.Length,
|
||||
CRC = _crc,
|
||||
UncompressedSize = _fileInfo != null ? (ulong)_fileInfo.Length : (ulong)_inStream!.Length,
|
||||
CRC = _crc!,
|
||||
IsDirectory = RVIO.Directory.Exists(ZipFilename),
|
||||
ModifiedTime = _fileInfo?.LastWriteTime,
|
||||
AccessedTime = _fileInfo?.LastAccessTime,
|
||||
@@ -87,11 +87,11 @@ namespace Compress.File
|
||||
|
||||
if (ZipOpen == ZipOpenType.OpenWrite)
|
||||
{
|
||||
_inStream.Flush();
|
||||
_inStream!.Flush();
|
||||
_inStream.Close();
|
||||
_inStream.Dispose();
|
||||
_inStream = null;
|
||||
_fileInfo = new FileInfo(_fileInfo.FullName);
|
||||
_fileInfo = new FileInfo(_fileInfo!.FullName);
|
||||
ZipOpen = ZipOpenType.Closed;
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ namespace Compress.File
|
||||
}
|
||||
|
||||
|
||||
public ZipReturn ZipFileOpen(Stream inStream)
|
||||
public ZipReturn ZipFileOpen(Stream? inStream)
|
||||
{
|
||||
ZipFileClose();
|
||||
ZipStatus = ZipStatus.None;
|
||||
@@ -173,17 +173,17 @@ namespace Compress.File
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ZipReturn ZipFileOpenReadStream(int index, out Stream stream, out ulong streamSize)
|
||||
public ZipReturn ZipFileOpenReadStream(int index, out Stream? stream, out ulong streamSize)
|
||||
{
|
||||
_inStream.Position = 0;
|
||||
_inStream!.Position = 0;
|
||||
stream = _inStream;
|
||||
streamSize = (ulong)_inStream.Length;
|
||||
return ZipReturn.ZipGood;
|
||||
}
|
||||
|
||||
public ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong uncompressedSize, ushort compressionMethod, out Stream stream, TimeStamps dateTime)
|
||||
public ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong uncompressedSize, ushort compressionMethod, out Stream? stream, TimeStamps? dateTime)
|
||||
{
|
||||
_inStream.Position = 0;
|
||||
_inStream!.Position = 0;
|
||||
stream = _inStream;
|
||||
return ZipReturn.ZipGood;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace Compress
|
||||
internal LocalFile()
|
||||
{ }
|
||||
|
||||
public string Filename { get; internal set; }
|
||||
public string? Filename { get; internal set; }
|
||||
public ulong UncompressedSize { get; internal set; }
|
||||
public byte[] CRC { get; internal set; }
|
||||
public byte[]? CRC { get; internal set; }
|
||||
|
||||
public bool IsDirectory { get; internal set; }
|
||||
|
||||
|
||||
@@ -23,13 +23,13 @@ namespace Compress.SevenZip
|
||||
}
|
||||
|
||||
|
||||
private List<SevenZipLocalFile> _localFiles = new();
|
||||
private List<SevenZipLocalFile> _localFiles = [];
|
||||
|
||||
private FileInfo _zipFileInfo;
|
||||
private FileInfo? _zipFileInfo;
|
||||
|
||||
private Stream _zipFs;
|
||||
private Stream? _zipFs;
|
||||
|
||||
private SignatureHeader _signatureHeader;
|
||||
private SignatureHeader? _signatureHeader;
|
||||
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace Compress.SevenZip
|
||||
}
|
||||
break;
|
||||
case ZipOpenType.OpenWrite:
|
||||
_zipFs.Flush();
|
||||
_zipFs!.Flush();
|
||||
_zipFs.Close();
|
||||
_zipFs.Dispose();
|
||||
if (_zipFileInfo != null)
|
||||
@@ -106,7 +106,7 @@ namespace Compress.SevenZip
|
||||
}
|
||||
|
||||
|
||||
private Header _header;
|
||||
private Header? _header;
|
||||
|
||||
public StringBuilder HeaderReport()
|
||||
{
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Compress.SevenZip
|
||||
}
|
||||
|
||||
|
||||
public ZipReturn ZipFileOpen(Stream inStream)
|
||||
public ZipReturn ZipFileOpen(Stream? inStream)
|
||||
{
|
||||
ZipFileClose();
|
||||
_zipFileInfo = null;
|
||||
@@ -74,12 +74,12 @@ namespace Compress.SevenZip
|
||||
try
|
||||
{
|
||||
SignatureHeader signatureHeader = new();
|
||||
if (!signatureHeader.Read(_zipFs))
|
||||
if (!signatureHeader.Read(_zipFs!))
|
||||
{
|
||||
return ZipReturn.ZipSignatureError;
|
||||
}
|
||||
|
||||
_baseOffset = _zipFs.Position;
|
||||
_baseOffset = _zipFs!.Position;
|
||||
|
||||
_zipFs.Seek(_baseOffset + (long)signatureHeader.NextHeaderOffset, SeekOrigin.Begin);
|
||||
byte[] mainHeader = new byte[signatureHeader.NextHeaderSize];
|
||||
@@ -126,7 +126,7 @@ namespace Compress.SevenZip
|
||||
if (_header == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < _header.FileInfo.Names.Length; i++)
|
||||
for (int i = 0; i < _header.FileInfo!.Names!.Length; i++)
|
||||
{
|
||||
SevenZipLocalFile lf = new() { Filename = _header.FileInfo.Names[i] };
|
||||
|
||||
@@ -134,13 +134,13 @@ namespace Compress.SevenZip
|
||||
{
|
||||
lf.StreamIndex = folderIndex;
|
||||
lf.StreamOffset = streamOffset;
|
||||
lf.UncompressedSize = _header.StreamsInfo.Folders[folderIndex].UnpackedStreamInfo[unpackedStreamsIndex].UnpackedSize;
|
||||
lf.CRC = Util.UIntToBytes(_header.StreamsInfo.Folders[folderIndex].UnpackedStreamInfo[unpackedStreamsIndex].Crc);
|
||||
lf.UncompressedSize = _header.StreamsInfo!.Folders![folderIndex].UnpackedStreamInfo![unpackedStreamsIndex].UnpackedSize;
|
||||
lf.CRC = Util.UIntToBytes(_header.StreamsInfo.Folders[folderIndex].UnpackedStreamInfo![unpackedStreamsIndex].Crc);
|
||||
|
||||
streamOffset += lf.UncompressedSize;
|
||||
unpackedStreamsIndex++;
|
||||
|
||||
if (unpackedStreamsIndex >= _header.StreamsInfo.Folders[folderIndex].UnpackedStreamInfo.Length)
|
||||
if (unpackedStreamsIndex >= _header.StreamsInfo.Folders[folderIndex].UnpackedStreamInfo!.Length)
|
||||
{
|
||||
folderIndex++;
|
||||
unpackedStreamsIndex = 0;
|
||||
|
||||
@@ -18,9 +18,9 @@ namespace Compress.SevenZip
|
||||
public partial class SevenZ
|
||||
{
|
||||
private int _streamIndex = -1;
|
||||
private Stream _stream;
|
||||
private Stream? _stream;
|
||||
|
||||
public ZipReturn ZipFileOpenReadStream(int index, out Stream stream, out ulong unCompressedSize)
|
||||
public ZipReturn ZipFileOpenReadStream(int index, out Stream? stream, out ulong unCompressedSize)
|
||||
{
|
||||
Debug.WriteLine("Opening File " + _localFiles[index].Filename);
|
||||
stream = null;
|
||||
@@ -42,7 +42,7 @@ namespace Compress.SevenZip
|
||||
int thisStreamIndex = _localFiles[index].StreamIndex;
|
||||
ulong streamOffset = _localFiles[index].StreamOffset;
|
||||
|
||||
if ((thisStreamIndex == _streamIndex) && (streamOffset >= (ulong)_stream.Position))
|
||||
if ((thisStreamIndex == _streamIndex) && (streamOffset >= (ulong)_stream!.Position))
|
||||
{
|
||||
stream = _stream;
|
||||
stream.Seek((long)_localFiles[index].StreamOffset - _stream.Position, SeekOrigin.Current);
|
||||
@@ -52,26 +52,26 @@ namespace Compress.SevenZip
|
||||
ZipFileCloseReadStream();
|
||||
_streamIndex = thisStreamIndex;
|
||||
|
||||
if (_header.StreamsInfo == null)
|
||||
if (_header?.StreamsInfo == null)
|
||||
{
|
||||
stream = null;
|
||||
return ZipReturn.ZipGood;
|
||||
}
|
||||
|
||||
Folder folder = _header.StreamsInfo.Folders[_streamIndex];
|
||||
Folder folder = _header.StreamsInfo.Folders![_streamIndex];
|
||||
|
||||
// first make the List of Decompressors streams
|
||||
int codersNeeded = folder.Coders.Length;
|
||||
int codersNeeded = folder.Coders!.Length;
|
||||
|
||||
List<InStreamSourceInfo> allInputStreams = new();
|
||||
List<InStreamSourceInfo> allInputStreams = [];
|
||||
for (int i = 0; i < codersNeeded; i++)
|
||||
{
|
||||
folder.Coders[i].DecoderStream = null;
|
||||
allInputStreams.AddRange(folder.Coders[i].InputStreamsSourceInfo);
|
||||
allInputStreams.AddRange(folder.Coders[i].InputStreamsSourceInfo!);
|
||||
}
|
||||
|
||||
// now use the binding pairs to links the outputs to the inputs
|
||||
int bindPairsCount = folder.BindPairs.Length;
|
||||
int bindPairsCount = folder.BindPairs!.Length;
|
||||
for (int i = 0; i < bindPairsCount; i++)
|
||||
{
|
||||
allInputStreams[(int)folder.BindPairs[i].InIndex].InStreamSource = InStreamSource.CompStreamOutput;
|
||||
@@ -80,17 +80,17 @@ namespace Compress.SevenZip
|
||||
}
|
||||
|
||||
// next use the stream indises to connect the remaining input streams from the sourcefile
|
||||
int packedStreamsCount = folder.PackedStreamIndices.Length;
|
||||
int packedStreamsCount = folder.PackedStreamIndices!.Length;
|
||||
for (int i = 0; i < packedStreamsCount; i++)
|
||||
{
|
||||
ulong packedStreamIndex = (ulong)i + folder.PackedStreamIndexBase;
|
||||
|
||||
// create and open the source file stream if needed
|
||||
if (_header.StreamsInfo.PackedStreams[packedStreamIndex].PackedStream == null)
|
||||
if (_header.StreamsInfo.PackedStreams![packedStreamIndex].PackedStream == null)
|
||||
{
|
||||
_header.StreamsInfo.PackedStreams[packedStreamIndex].PackedStream = CloneStream(_zipFs);
|
||||
_header.StreamsInfo.PackedStreams[packedStreamIndex].PackedStream = CloneStream(_zipFs!)!;
|
||||
}
|
||||
_header.StreamsInfo.PackedStreams[packedStreamIndex].PackedStream.Seek(
|
||||
_header.StreamsInfo.PackedStreams[packedStreamIndex].PackedStream!.Seek(
|
||||
_baseOffset + (long)_header.StreamsInfo.PackedStreams[packedStreamIndex].StreamPosition, SeekOrigin.Begin);
|
||||
|
||||
|
||||
@@ -117,9 +117,9 @@ namespace Compress.SevenZip
|
||||
inputCoders.Clear();
|
||||
for (int j = 0; j < (int)coder.NumInStreams; j++)
|
||||
{
|
||||
if (coder.InputStreamsSourceInfo[j].InStreamSource == InStreamSource.FileStream)
|
||||
if (coder.InputStreamsSourceInfo![j].InStreamSource == InStreamSource.FileStream)
|
||||
{
|
||||
inputCoders.Add(_header.StreamsInfo.PackedStreams[coder.InputStreamsSourceInfo[j].InStreamIndex].PackedStream);
|
||||
inputCoders.Add(_header.StreamsInfo.PackedStreams![coder.InputStreamsSourceInfo[j].InStreamIndex].PackedStream!);
|
||||
}
|
||||
else if (coder.InputStreamsSourceInfo[j].InStreamSource == InStreamSource.CompStreamOutput)
|
||||
{
|
||||
@@ -127,7 +127,7 @@ namespace Compress.SevenZip
|
||||
{
|
||||
break;
|
||||
}
|
||||
inputCoders.Add(folder.Coders[coder.InputStreamsSourceInfo[j].InStreamIndex].DecoderStream);
|
||||
inputCoders.Add(folder.Coders[coder.InputStreamsSourceInfo[j].InStreamIndex].DecoderStream!);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -145,16 +145,16 @@ namespace Compress.SevenZip
|
||||
coder.DecoderStream = inputCoders[0];
|
||||
break;
|
||||
case DecompressType.Delta:
|
||||
coder.DecoderStream = new Delta(folder.Coders[i].Properties, inputCoders[0]);
|
||||
coder.DecoderStream = new Delta(folder.Coders[i].Properties!, inputCoders[0]);
|
||||
break;
|
||||
case DecompressType.LZMA:
|
||||
coder.DecoderStream = new LzmaStream(folder.Coders[i].Properties, inputCoders[0]);
|
||||
coder.DecoderStream = new LzmaStream(folder.Coders[i].Properties!, inputCoders[0]);
|
||||
break;
|
||||
case DecompressType.LZMA2:
|
||||
coder.DecoderStream = new LzmaStream(folder.Coders[i].Properties, inputCoders[0]);
|
||||
coder.DecoderStream = new LzmaStream(folder.Coders[i].Properties!, inputCoders[0]);
|
||||
break;
|
||||
case DecompressType.PPMd:
|
||||
coder.DecoderStream = new PpmdStream(new PpmdProperties(folder.Coders[i].Properties), inputCoders[0], false);
|
||||
coder.DecoderStream = new PpmdStream(new PpmdProperties(folder.Coders[i].Properties!), inputCoders[0], false);
|
||||
break;
|
||||
case DecompressType.BZip2:
|
||||
coder.DecoderStream = new CBZip2InputStream(inputCoders[0], false);
|
||||
@@ -194,7 +194,7 @@ namespace Compress.SevenZip
|
||||
}
|
||||
|
||||
stream = folder.Coders[outputStream].DecoderStream;
|
||||
stream.Seek((long)_localFiles[index].StreamOffset, SeekOrigin.Current);
|
||||
stream!.Seek((long)_localFiles[index].StreamOffset, SeekOrigin.Current);
|
||||
|
||||
_stream = stream;
|
||||
|
||||
@@ -208,12 +208,12 @@ namespace Compress.SevenZip
|
||||
|
||||
}
|
||||
|
||||
private Stream CloneStream(Stream s)
|
||||
private Stream? CloneStream(Stream s)
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
case System.IO.FileStream _:
|
||||
int errorCode = FileStream.OpenFileRead(ZipFilename, out Stream streamOut);
|
||||
int errorCode = FileStream.OpenFileRead(ZipFilename, out Stream? streamOut);
|
||||
return errorCode != 0 ? null : streamOut;
|
||||
|
||||
case MemoryStream memStream:
|
||||
@@ -233,20 +233,20 @@ namespace Compress.SevenZip
|
||||
{
|
||||
if (_streamIndex != -1)
|
||||
{
|
||||
if (_header.StreamsInfo != null)
|
||||
if (_header!.StreamsInfo != null)
|
||||
{
|
||||
Folder folder = _header.StreamsInfo.Folders[_streamIndex];
|
||||
Folder folder = _header.StreamsInfo.Folders![_streamIndex];
|
||||
|
||||
foreach (Coder c in folder.Coders)
|
||||
foreach (Coder c in folder.Coders!)
|
||||
{
|
||||
Stream ds = c?.DecoderStream;
|
||||
Stream? ds = c?.DecoderStream;
|
||||
if (ds == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ds.Close();
|
||||
ds.Dispose();
|
||||
c.DecoderStream = null;
|
||||
c!.DecoderStream = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,7 +254,7 @@ namespace Compress.SevenZip
|
||||
|
||||
if (_header?.StreamsInfo != null)
|
||||
{
|
||||
foreach (PackedStreamInfo psi in _header.StreamsInfo.PackedStreams)
|
||||
foreach (PackedStreamInfo psi in _header.StreamsInfo.PackedStreams!)
|
||||
{
|
||||
if (psi?.PackedStream == null)
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Compress.SevenZip
|
||||
|
||||
private bool IsRomVault7Z(long testBaseOffset, ulong testHeaderPos, ulong testHeaderLength, uint testHeaderCRC)
|
||||
{
|
||||
long length = _zipFs.Length;
|
||||
long length = _zipFs!.Length;
|
||||
if (length < 32)
|
||||
{
|
||||
return false;
|
||||
@@ -87,7 +87,7 @@ namespace Compress.SevenZip
|
||||
|
||||
// read fist 128 bytes, pad with zeros if less bytes
|
||||
int bufferPos = 0;
|
||||
_zipFs.Seek(0, SeekOrigin.Begin);
|
||||
_zipFs!.Seek(0, SeekOrigin.Begin);
|
||||
int ar = _zipFs.Read(buffer, bufferPos, crcsz);
|
||||
if (ar < crcsz)
|
||||
{
|
||||
|
||||
@@ -58,14 +58,14 @@ namespace Compress.SevenZip
|
||||
_header = new Header();
|
||||
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryWriter bw = new(_zipFs, Encoding.UTF8))
|
||||
using (BinaryWriter bw = new(_zipFs!, Encoding.UTF8))
|
||||
#else
|
||||
using (BinaryWriter bw = new(_zipFs, Encoding.UTF8, true))
|
||||
using (BinaryWriter bw = new(_zipFs!, Encoding.UTF8, true))
|
||||
#endif
|
||||
{
|
||||
_signatureHeader.Write(bw);
|
||||
}
|
||||
_baseOffset = _zipFs.Position;
|
||||
_baseOffset = _zipFs!.Position;
|
||||
|
||||
|
||||
_packedOutStreams = new List<outStreams>();
|
||||
@@ -167,7 +167,7 @@ namespace Compress.SevenZip
|
||||
|
||||
outStreams newStream = new()
|
||||
{
|
||||
packedStart = (ulong)_zipFs.Position,
|
||||
packedStart = (ulong)_zipFs!.Position,
|
||||
compType = _compType,
|
||||
packedSize = 0,
|
||||
unpackedStreams = new List<UnpackedStreamInfo>()
|
||||
@@ -200,11 +200,11 @@ namespace Compress.SevenZip
|
||||
break;
|
||||
}
|
||||
|
||||
_packedOutStreams.Add(newStream);
|
||||
_packedOutStreams!.Add(newStream);
|
||||
#endif
|
||||
|
||||
unpackedStreamInfo = new UnpackedStreamInfo { UnpackedSize = uncompressedSize };
|
||||
_packedOutStreams[_packedOutStreams.Count - 1].unpackedStreams.Add(unpackedStreamInfo);
|
||||
_packedOutStreams[_packedOutStreams.Count - 1].unpackedStreams!.Add(unpackedStreamInfo);
|
||||
|
||||
stream = _compressStream;
|
||||
return ZipReturn.ZipGood;
|
||||
@@ -222,12 +222,12 @@ namespace Compress.SevenZip
|
||||
#if !solid
|
||||
if (unpackedStreamInfo != null)
|
||||
{
|
||||
if (_packedOutStreams[_packedOutStreams.Count - 1].compType != SevenZipCompressType.uncompressed)
|
||||
if (_packedOutStreams![_packedOutStreams.Count - 1].compType != SevenZipCompressType.uncompressed)
|
||||
{
|
||||
_compressStream.Flush();
|
||||
_compressStream!.Flush();
|
||||
_compressStream.Close();
|
||||
}
|
||||
_packedOutStreams[_packedOutStreams.Count - 1].packedSize = (ulong)_zipFs.Position - _packedOutStreams[_packedOutStreams.Count - 1].packedStart;
|
||||
_packedOutStreams[_packedOutStreams.Count - 1].packedSize = (ulong)_zipFs!.Position - _packedOutStreams[_packedOutStreams.Count - 1].packedStart;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Compress.SevenZip
|
||||
int fileCount = _localFiles.Count;
|
||||
|
||||
//FileInfo
|
||||
_header.FileInfo = new Structure.FileInfo
|
||||
_header!.FileInfo = new Structure.FileInfo
|
||||
{
|
||||
Names = new string[fileCount]
|
||||
};
|
||||
@@ -22,7 +22,7 @@ namespace Compress.SevenZip
|
||||
ulong emptyFileCount = 0;
|
||||
for (int i = 0; i < fileCount; i++)
|
||||
{
|
||||
_header.FileInfo.Names[i] = _localFiles[i].Filename;
|
||||
_header.FileInfo.Names[i] = _localFiles[i].Filename!;
|
||||
|
||||
if (_localFiles[i].UncompressedSize != 0)
|
||||
{
|
||||
@@ -83,7 +83,7 @@ namespace Compress.SevenZip
|
||||
|
||||
_header.StreamsInfo = new StreamsInfo { PackPosition = 0 };
|
||||
|
||||
_header.StreamsInfo.PackedStreams = new PackedStreamInfo[_packedOutStreams.Count];
|
||||
_header.StreamsInfo.PackedStreams = new PackedStreamInfo[_packedOutStreams!.Count];
|
||||
for (int i = 0; i < _packedOutStreams.Count; i++)
|
||||
{
|
||||
_header.StreamsInfo.PackedStreams[i] = new PackedStreamInfo { PackedSize = _packedOutStreams[i].packedSize };
|
||||
@@ -93,7 +93,7 @@ namespace Compress.SevenZip
|
||||
for (int i = 0; i < _packedOutStreams.Count; i++)
|
||||
{
|
||||
ulong unpackedStreamSize = 0;
|
||||
foreach (UnpackedStreamInfo v in _packedOutStreams[i].unpackedStreams)
|
||||
foreach (UnpackedStreamInfo v in _packedOutStreams[i].unpackedStreams!)
|
||||
unpackedStreamSize += v.UnpackedSize;
|
||||
|
||||
_header.StreamsInfo.Folders[i] = new Folder()
|
||||
@@ -109,7 +109,7 @@ namespace Compress.SevenZip
|
||||
},
|
||||
PackedStreamIndices = new ulong[] { (ulong)i },
|
||||
UnpackedStreamSizes = new ulong[] { unpackedStreamSize },
|
||||
UnpackedStreamInfo = _packedOutStreams[i].unpackedStreams.ToArray(),
|
||||
UnpackedStreamInfo = _packedOutStreams[i].unpackedStreams!.ToArray(),
|
||||
UnpackCRC = null
|
||||
};
|
||||
}
|
||||
@@ -135,7 +135,7 @@ namespace Compress.SevenZip
|
||||
#else
|
||||
using BinaryWriter headerBw = new(headerMem, Encoding.UTF8, true);
|
||||
#endif
|
||||
_header.WriteHeader(headerBw);
|
||||
_header!.WriteHeader(headerBw);
|
||||
|
||||
newHeaderByte = new byte[headerMem.Length];
|
||||
headerMem.Position = 0;
|
||||
@@ -145,7 +145,7 @@ namespace Compress.SevenZip
|
||||
uint mainHeaderCRC = CRC.CalculateDigest(newHeaderByte, 0, (uint)newHeaderByte.Length);
|
||||
|
||||
#region Header Compression
|
||||
long packedHeaderPos = _zipFs.Position;
|
||||
long packedHeaderPos = _zipFs!.Position;
|
||||
LzmaEncoderProperties ep = new(true, GetDictionarySizeFromUncompressedSize((ulong)newHeaderByte.Length), 64);
|
||||
LzmaStream lzs = new(ep, false, _zipFs);
|
||||
byte[] lzmaStreamProperties = lzs.Properties;
|
||||
@@ -206,7 +206,7 @@ namespace Compress.SevenZip
|
||||
WriteRomVault7Zip(bw, headerPosition, (ulong)newHeaderByte.Length, mainHeaderCRC);
|
||||
|
||||
_zipFs.Write(newHeaderByte, 0, newHeaderByte.Length);
|
||||
_signatureHeader.WriteFinal(bw, headerPosition, (ulong)newHeaderByte.Length, mainHeaderCRC);
|
||||
_signatureHeader!.WriteFinal(bw, headerPosition, (ulong)newHeaderByte.Length, mainHeaderCRC);
|
||||
}
|
||||
_zipFs.Flush();
|
||||
_zipFs.Close();
|
||||
|
||||
@@ -36,16 +36,16 @@ namespace Compress.SevenZip.Structure
|
||||
|
||||
public class Coder
|
||||
{
|
||||
public byte[] Method;
|
||||
public byte[]? Method;
|
||||
public ulong NumInStreams;
|
||||
public ulong NumOutStreams;
|
||||
public byte[] Properties;
|
||||
public byte[]? Properties;
|
||||
|
||||
/************Local Variables***********/
|
||||
public DecompressType DecoderType;
|
||||
public bool OutputUsedInternally = false;
|
||||
public InStreamSourceInfo[] InputStreamsSourceInfo;
|
||||
public Stream DecoderStream;
|
||||
public InStreamSourceInfo[]? InputStreamsSourceInfo;
|
||||
public Stream? DecoderStream;
|
||||
|
||||
public void Read(BinaryReader br)
|
||||
{
|
||||
@@ -120,7 +120,7 @@ namespace Compress.SevenZip.Structure
|
||||
|
||||
public void Write(BinaryWriter bw)
|
||||
{
|
||||
byte flags = (byte)Method.Length;
|
||||
byte flags = (byte)Method!.Length;
|
||||
if ((NumInStreams != 1) || (NumOutStreams != 1))
|
||||
{
|
||||
flags = (byte)(flags | 0x10);
|
||||
@@ -152,10 +152,10 @@ namespace Compress.SevenZip.Structure
|
||||
|
||||
public void Report(ref StringBuilder sb)
|
||||
{
|
||||
sb.AppendLine($" Method[] = {Method.ToArrayString()} : {DecoderType}");
|
||||
sb.AppendLine($" Method[] = {Method!.ToArrayString()} : {DecoderType}");
|
||||
sb.AppendLine($" NumInStreams = {NumInStreams}");
|
||||
sb.AppendLine($" NumOutStreams = {NumOutStreams}");
|
||||
sb.AppendLine($" Properties[] = {Properties.ToArrayString()}");
|
||||
sb.AppendLine($" Properties[] = {Properties!.ToArrayString()}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ namespace Compress.SevenZip.Structure
|
||||
{
|
||||
public class FileInfo
|
||||
{
|
||||
public string[] Names;
|
||||
public bool[] EmptyStreamFlags;
|
||||
public bool[] EmptyFileFlags;
|
||||
public uint[] Attributes;
|
||||
public ulong[] TimeCreation;
|
||||
public ulong[] TimeLastAccess;
|
||||
public ulong[] TimeLastWrite;
|
||||
public string[]? Names;
|
||||
public bool[]? EmptyStreamFlags;
|
||||
public bool[]? EmptyFileFlags;
|
||||
public uint[]? Attributes;
|
||||
public ulong[]? TimeCreation;
|
||||
public ulong[]? TimeLastAccess;
|
||||
public ulong[]? TimeLastWrite;
|
||||
|
||||
public void Read(BinaryReader br)
|
||||
{
|
||||
@@ -92,7 +92,7 @@ namespace Compress.SevenZip.Structure
|
||||
public void Write(BinaryWriter bw)
|
||||
{
|
||||
bw.Write((byte)HeaderProperty.kFilesInfo);
|
||||
bw.WriteEncodedUInt64((ulong)Names.Length);
|
||||
bw.WriteEncodedUInt64((ulong)Names!.Length);
|
||||
|
||||
|
||||
byte[] namebyte;
|
||||
|
||||
@@ -7,13 +7,13 @@ namespace Compress.SevenZip.Structure
|
||||
{
|
||||
public class Folder
|
||||
{
|
||||
public Coder[] Coders;
|
||||
public BindPair[] BindPairs;
|
||||
public Coder[]? Coders;
|
||||
public BindPair[]? BindPairs;
|
||||
public ulong PackedStreamIndexBase;
|
||||
public ulong[] PackedStreamIndices;
|
||||
public ulong[] UnpackedStreamSizes;
|
||||
public ulong[]? PackedStreamIndices;
|
||||
public ulong[]? UnpackedStreamSizes;
|
||||
public uint? UnpackCRC;
|
||||
public UnpackedStreamInfo[] UnpackedStreamInfo;
|
||||
public UnpackedStreamInfo[]? UnpackedStreamInfo;
|
||||
|
||||
|
||||
private void ReadFolder(BinaryReader br)
|
||||
@@ -80,7 +80,7 @@ namespace Compress.SevenZip.Structure
|
||||
private void ReadUnpackedStreamSize(BinaryReader br)
|
||||
{
|
||||
ulong outStreams = 0;
|
||||
foreach (Coder c in Coders)
|
||||
foreach (Coder c in Coders!)
|
||||
{
|
||||
outStreams += c.NumOutStreams;
|
||||
}
|
||||
@@ -95,7 +95,7 @@ namespace Compress.SevenZip.Structure
|
||||
private ulong GetUnpackSize()
|
||||
{
|
||||
ulong outStreams = 0;
|
||||
foreach (Coder coder in Coders)
|
||||
foreach (Coder coder in Coders!)
|
||||
{
|
||||
outStreams += coder.NumInStreams;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ namespace Compress.SevenZip.Structure
|
||||
for (ulong j = 0; j < outStreams; j++)
|
||||
{
|
||||
bool found = false;
|
||||
foreach (BindPair bindPair in BindPairs)
|
||||
foreach (BindPair bindPair in BindPairs!)
|
||||
{
|
||||
if (bindPair.OutIndex != j)
|
||||
{
|
||||
@@ -116,7 +116,7 @@ namespace Compress.SevenZip.Structure
|
||||
|
||||
if (!found)
|
||||
{
|
||||
return UnpackedStreamSizes[j];
|
||||
return UnpackedStreamSizes![j]!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace Compress.SevenZip.Structure
|
||||
}
|
||||
|
||||
|
||||
public static void ReadUnPackInfo(BinaryReader br, out Folder[] Folders)
|
||||
public static void ReadUnPackInfo(BinaryReader br, out Folder[]? Folders)
|
||||
{
|
||||
Folders = null;
|
||||
for (; ; )
|
||||
@@ -149,7 +149,7 @@ namespace Compress.SevenZip.Structure
|
||||
Folders[i] = new Folder();
|
||||
Folders[i].ReadFolder(br);
|
||||
Folders[i].PackedStreamIndexBase = folderIndex;
|
||||
folderIndex += (ulong)Folders[i].PackedStreamIndices.Length;
|
||||
folderIndex += (ulong)Folders[i].PackedStreamIndices!.Length;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -165,7 +165,7 @@ namespace Compress.SevenZip.Structure
|
||||
|
||||
case HeaderProperty.kCodersUnPackSize:
|
||||
{
|
||||
for (uint i = 0; i < Folders.Length; i++)
|
||||
for (uint i = 0; i < Folders!.Length; i++)
|
||||
{
|
||||
Folders[i].ReadUnpackedStreamSize(br);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ namespace Compress.SevenZip.Structure
|
||||
|
||||
case HeaderProperty.kCRC:
|
||||
{
|
||||
Util.UnPackCRCs(br, (ulong)Folders.Length, out uint?[] crcs);
|
||||
Util.UnPackCRCs(br, (ulong)Folders!.Length, out uint?[] crcs);
|
||||
for (int i = 0; i < Folders.Length; i++)
|
||||
{
|
||||
Folders[i].UnpackCRC = crcs[i];
|
||||
@@ -193,7 +193,7 @@ namespace Compress.SevenZip.Structure
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReadSubStreamsInfo(BinaryReader br, ref Folder[] Folders)
|
||||
public static void ReadSubStreamsInfo(BinaryReader br, ref Folder[]? Folders)
|
||||
{
|
||||
for (; ; )
|
||||
{
|
||||
@@ -202,13 +202,13 @@ namespace Compress.SevenZip.Structure
|
||||
{
|
||||
case HeaderProperty.kNumUnPackStream:
|
||||
{
|
||||
for (int f = 0; f < Folders.Length; f++)
|
||||
for (int f = 0; f < Folders!.Length; f++)
|
||||
{
|
||||
int numStreams = (int)br.ReadEncodedUInt64();
|
||||
Folders[f].UnpackedStreamInfo = new UnpackedStreamInfo[numStreams];
|
||||
for (int i = 0; i < numStreams; i++)
|
||||
{
|
||||
Folders[f].UnpackedStreamInfo[i] = new UnpackedStreamInfo();
|
||||
Folders[f].UnpackedStreamInfo![i] = new UnpackedStreamInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,11 +217,11 @@ namespace Compress.SevenZip.Structure
|
||||
|
||||
case HeaderProperty.kSize:
|
||||
{
|
||||
for (int f = 0; f < Folders.Length; f++)
|
||||
for (int f = 0; f < Folders!.Length; f++)
|
||||
{
|
||||
Folder folder = Folders[f];
|
||||
|
||||
if (folder.UnpackedStreamInfo.Length == 0)
|
||||
if (folder.UnpackedStreamInfo!.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -244,7 +244,7 @@ namespace Compress.SevenZip.Structure
|
||||
case HeaderProperty.kCRC:
|
||||
{
|
||||
ulong numCRC = 0;
|
||||
foreach (Folder folder in Folders)
|
||||
foreach (Folder folder in Folders!)
|
||||
{
|
||||
if (folder.UnpackedStreamInfo == null)
|
||||
{
|
||||
@@ -266,7 +266,7 @@ namespace Compress.SevenZip.Structure
|
||||
for (uint i = 0; i < Folders.Length; i++)
|
||||
{
|
||||
Folder folder = Folders[i];
|
||||
if ((folder.UnpackedStreamInfo.Length == 1) && folder.UnpackCRC.HasValue)
|
||||
if ((folder.UnpackedStreamInfo!.Length == 1) && folder.UnpackCRC.HasValue)
|
||||
{
|
||||
folder.UnpackedStreamInfo[0].Crc = folder.UnpackCRC;
|
||||
}
|
||||
@@ -293,7 +293,7 @@ namespace Compress.SevenZip.Structure
|
||||
|
||||
private void WriteFolder(BinaryWriter bw)
|
||||
{
|
||||
ulong numCoders = (ulong)Coders.Length;
|
||||
ulong numCoders = (ulong)Coders!.Length;
|
||||
bw.WriteEncodedUInt64(numCoders);
|
||||
for (ulong i = 0; i < numCoders; i++)
|
||||
{
|
||||
@@ -303,7 +303,7 @@ namespace Compress.SevenZip.Structure
|
||||
ulong numBindingPairs = BindPairs == null ? 0 : (ulong)BindPairs.Length;
|
||||
for (ulong i = 0; i < numBindingPairs; i++)
|
||||
{
|
||||
BindPairs[i].Write(bw);
|
||||
BindPairs![i].Write(bw);
|
||||
}
|
||||
|
||||
//need to look at PAckedStreamIndices but don't need them for basic writing I am doing
|
||||
@@ -311,7 +311,7 @@ namespace Compress.SevenZip.Structure
|
||||
|
||||
private void WriteUnpackedStreamSize(BinaryWriter bw)
|
||||
{
|
||||
ulong numUnpackedStreamSizes = (ulong)UnpackedStreamSizes.Length;
|
||||
ulong numUnpackedStreamSizes = (ulong)UnpackedStreamSizes!.Length;
|
||||
for (ulong i = 0; i < numUnpackedStreamSizes; i++)
|
||||
{
|
||||
bw.WriteEncodedUInt64(UnpackedStreamSizes[i]);
|
||||
@@ -362,7 +362,7 @@ namespace Compress.SevenZip.Structure
|
||||
bw.Write((byte)HeaderProperty.kNumUnPackStream);
|
||||
for (int f = 0; f < Folders.Length; f++)
|
||||
{
|
||||
ulong numStreams = (ulong)Folders[f].UnpackedStreamInfo.Length;
|
||||
ulong numStreams = (ulong)Folders[f].UnpackedStreamInfo!.Length;
|
||||
bw.WriteEncodedUInt64(numStreams);
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ namespace Compress.SevenZip.Structure
|
||||
for (int f = 0; f < Folders.Length; f++)
|
||||
{
|
||||
Folder folder = Folders[f];
|
||||
for (int i = 0; i < folder.UnpackedStreamInfo.Length - 1; i++)
|
||||
for (int i = 0; i < folder.UnpackedStreamInfo!.Length - 1; i++)
|
||||
{
|
||||
bw.WriteEncodedUInt64(folder.UnpackedStreamInfo[i].UnpackedSize);
|
||||
}
|
||||
@@ -382,9 +382,9 @@ namespace Compress.SevenZip.Structure
|
||||
for (int f = 0; f < Folders.Length; f++)
|
||||
{
|
||||
Folder folder = Folders[f];
|
||||
for (int i = 0; i < folder.UnpackedStreamInfo.Length; i++)
|
||||
for (int i = 0; i < folder.UnpackedStreamInfo!.Length; i++)
|
||||
{
|
||||
bw.Write(Util.UIntToBytes(folder.UnpackedStreamInfo[i].Crc));
|
||||
bw.Write(Util.UIntToBytes(folder.UnpackedStreamInfo[i].Crc)!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,8 +420,8 @@ namespace Compress.SevenZip.Structure
|
||||
}
|
||||
|
||||
sb.AppendLine($" PackedStreamIndexBase = {PackedStreamIndexBase}");
|
||||
sb.AppendLine($" PackedStreamIndices[] = {PackedStreamIndices.ToArrayString()}");
|
||||
sb.AppendLine($" UnpackedStreamSizes[] = {UnpackedStreamSizes.ToArrayString()}");
|
||||
sb.AppendLine($" PackedStreamIndices[] = {PackedStreamIndices!.ToArrayString()}");
|
||||
sb.AppendLine($" UnpackedStreamSizes[] = {UnpackedStreamSizes!.ToArrayString()}");
|
||||
sb.AppendLine($" UnpackCRC = {UnpackCRC.ToHex()}");
|
||||
|
||||
if (UnpackedStreamInfo == null)
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace Compress.SevenZip.Structure
|
||||
{
|
||||
public class Header
|
||||
{
|
||||
public StreamsInfo StreamsInfo;
|
||||
public FileInfo FileInfo;
|
||||
public StreamsInfo? StreamsInfo;
|
||||
public FileInfo? FileInfo;
|
||||
|
||||
public void Read(BinaryReader br)
|
||||
{
|
||||
@@ -40,12 +40,12 @@ namespace Compress.SevenZip.Structure
|
||||
public void WriteHeader(BinaryWriter bw)
|
||||
{
|
||||
bw.Write((byte)HeaderProperty.kHeader);
|
||||
StreamsInfo.Write(bw);
|
||||
FileInfo.Write(bw);
|
||||
StreamsInfo!.Write(bw);
|
||||
FileInfo!.Write(bw);
|
||||
bw.Write((byte)HeaderProperty.kEnd);
|
||||
}
|
||||
|
||||
public static ZipReturn ReadHeaderOrPackedHeader(Stream stream, long baseOffset, out Header header)
|
||||
public static ZipReturn ReadHeaderOrPackedHeader(Stream stream, long baseOffset, out Header? header)
|
||||
{
|
||||
header = null;
|
||||
|
||||
@@ -62,25 +62,25 @@ namespace Compress.SevenZip.Structure
|
||||
StreamsInfo streamsInfo = new();
|
||||
streamsInfo.Read(br);
|
||||
|
||||
if (streamsInfo.Folders.Length > 1)
|
||||
if (streamsInfo.Folders!.Length > 1)
|
||||
{
|
||||
return ZipReturn.ZipUnsupportedCompression;
|
||||
}
|
||||
|
||||
Folder firstFolder = streamsInfo.Folders[0];
|
||||
if (firstFolder.Coders.Length > 1)
|
||||
if (firstFolder.Coders!.Length > 1)
|
||||
{
|
||||
return ZipReturn.ZipUnsupportedCompression;
|
||||
}
|
||||
|
||||
byte[] method = firstFolder.Coders[0].Method;
|
||||
byte[] method = firstFolder.Coders[0].Method!;
|
||||
if (!((method.Length == 3) && (method[0] == 3) && (method[1] == 1) && (method[2] == 1))) // LZMA
|
||||
{
|
||||
return ZipReturn.ZipUnsupportedCompression;
|
||||
}
|
||||
|
||||
stream.Seek(baseOffset + (long)streamsInfo.PackPosition, SeekOrigin.Begin);
|
||||
using (LzmaStream decoder = new(firstFolder.Coders[0].Properties, stream))
|
||||
using (LzmaStream decoder = new(firstFolder.Coders[0].Properties!, stream))
|
||||
{
|
||||
ZipReturn zr = ReadHeaderOrPackedHeader(decoder, baseOffset, out header);
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Compress.SevenZip.Structure
|
||||
public ulong PackedSize;
|
||||
public ulong? Crc;
|
||||
public ulong StreamPosition;
|
||||
public Stream PackedStream;
|
||||
public Stream? PackedStream;
|
||||
|
||||
public static void Read(BinaryReader br, out ulong packPosition, out PackedStreamInfo[] packedStreams)
|
||||
{
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace Compress.SevenZip.Structure
|
||||
public class StreamsInfo
|
||||
{
|
||||
public ulong PackPosition;
|
||||
public PackedStreamInfo[] PackedStreams;
|
||||
public Folder[] Folders;
|
||||
public PackedStreamInfo[]? PackedStreams;
|
||||
public Folder[]? Folders;
|
||||
|
||||
public void Read(BinaryReader br)
|
||||
{
|
||||
@@ -41,16 +41,16 @@ namespace Compress.SevenZip.Structure
|
||||
public void Write(BinaryWriter bw)
|
||||
{
|
||||
bw.Write((byte)HeaderProperty.kMainStreamsInfo);
|
||||
PackedStreamInfo.Write(bw, PackPosition, PackedStreams);
|
||||
Folder.WriteUnPackInfo(bw, Folders);
|
||||
Folder.WriteSubStreamsInfo(bw, Folders);
|
||||
PackedStreamInfo.Write(bw, PackPosition, PackedStreams!);
|
||||
Folder.WriteUnPackInfo(bw, Folders!);
|
||||
Folder.WriteSubStreamsInfo(bw, Folders!);
|
||||
bw.Write((byte)HeaderProperty.kEnd);
|
||||
}
|
||||
|
||||
public void WriteHeader(BinaryWriter bw)
|
||||
{
|
||||
PackedStreamInfo.Write(bw, PackPosition, PackedStreams);
|
||||
Folder.WriteUnPackInfo(bw, Folders);
|
||||
PackedStreamInfo.Write(bw, PackPosition, PackedStreams!);
|
||||
Folder.WriteUnPackInfo(bw, Folders!);
|
||||
bw.Write((byte)HeaderProperty.kEnd);
|
||||
}
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ namespace Compress.SevenZip
|
||||
{
|
||||
if (digestsDefined[i])
|
||||
{
|
||||
bw.Write((uint)digests[i]);
|
||||
bw.Write((uint)digests[i]!);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,7 +334,7 @@ namespace Compress.SevenZip
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] UIntToBytes(uint? crc)
|
||||
public static byte[]? UIntToBytes(uint? crc)
|
||||
{
|
||||
if (crc == null)
|
||||
{
|
||||
|
||||
@@ -104,8 +104,8 @@ namespace Compress.Support.Compression.BZip2
|
||||
private char[] selector = new char[BZip2Constants.MAX_SELECTORS];
|
||||
private char[] selectorMtf = new char[BZip2Constants.MAX_SELECTORS];
|
||||
|
||||
private int[] tt;
|
||||
private char[] ll8;
|
||||
private int[]? tt;
|
||||
private char[]? ll8;
|
||||
|
||||
/*
|
||||
freq table collected to save a pass over the data
|
||||
@@ -118,7 +118,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
private int[][] perm = InitIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE);
|
||||
private int[] minLens = new int[BZip2Constants.N_GROUPS];
|
||||
|
||||
private Stream bsStream;
|
||||
private Stream? bsStream;
|
||||
|
||||
private bool streamEnd = false;
|
||||
|
||||
@@ -216,7 +216,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
|
||||
private bool Initialize(bool isFirstStream)
|
||||
{
|
||||
int magic0 = bsStream.ReadByte();
|
||||
int magic0 = bsStream!.ReadByte();
|
||||
int magic1 = bsStream.ReadByte();
|
||||
int magic2 = bsStream.ReadByte();
|
||||
if (magic0 == -1 && !isFirstStream)
|
||||
@@ -360,7 +360,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
int thech = '\0';
|
||||
try
|
||||
{
|
||||
thech = (char)bsStream.ReadByte();
|
||||
thech = (char)bsStream!.ReadByte();
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
@@ -631,7 +631,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
char thech = '\0';
|
||||
try
|
||||
{
|
||||
thech = (char)bsStream.ReadByte();
|
||||
thech = (char)bsStream!.ReadByte();
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
@@ -700,7 +700,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
char thech = '\0';
|
||||
try
|
||||
{
|
||||
thech = (char)bsStream.ReadByte();
|
||||
thech = (char)bsStream!.ReadByte();
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
@@ -731,7 +731,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
while (s > 0)
|
||||
{
|
||||
last++;
|
||||
ll8[last] = ch;
|
||||
ll8![last] = ch;
|
||||
s--;
|
||||
}
|
||||
|
||||
@@ -752,7 +752,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
|
||||
tmp = yy[nextSym - 1];
|
||||
unzftab[seqToUnseq[tmp]]++;
|
||||
ll8[last] = seqToUnseq[tmp];
|
||||
ll8![last] = seqToUnseq[tmp];
|
||||
|
||||
/*
|
||||
This loop is hammered during decompression,
|
||||
@@ -797,7 +797,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
char thech = '\0';
|
||||
try
|
||||
{
|
||||
thech = (char)bsStream.ReadByte();
|
||||
thech = (char)bsStream!.ReadByte();
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
@@ -822,7 +822,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
|
||||
private void SetupBlock()
|
||||
{
|
||||
int[] cftab = new int[257];
|
||||
int[]? cftab = new int[257];
|
||||
char ch;
|
||||
|
||||
cftab[0] = 0;
|
||||
@@ -837,13 +837,13 @@ namespace Compress.Support.Compression.BZip2
|
||||
|
||||
for (i = 0; i <= last; i++)
|
||||
{
|
||||
ch = (char)ll8[i];
|
||||
tt[cftab[ch]] = i;
|
||||
ch = (char)ll8![i];
|
||||
tt![cftab[ch]] = i;
|
||||
cftab[ch]++;
|
||||
}
|
||||
cftab = null;
|
||||
|
||||
tPos = tt[origPtr];
|
||||
tPos = tt![origPtr];
|
||||
|
||||
count = 0;
|
||||
i2 = 0;
|
||||
@@ -866,8 +866,8 @@ namespace Compress.Support.Compression.BZip2
|
||||
if (i2 <= last)
|
||||
{
|
||||
chPrev = ch2;
|
||||
ch2 = ll8[tPos];
|
||||
tPos = tt[tPos];
|
||||
ch2 = ll8![tPos];
|
||||
tPos = tt![tPos];
|
||||
if (rNToGo == 0)
|
||||
{
|
||||
rNToGo = BZip2Constants.rNums[rTPos];
|
||||
@@ -898,8 +898,8 @@ namespace Compress.Support.Compression.BZip2
|
||||
if (i2 <= last)
|
||||
{
|
||||
chPrev = ch2;
|
||||
ch2 = ll8[tPos];
|
||||
tPos = tt[tPos];
|
||||
ch2 = ll8![tPos];
|
||||
tPos = tt![tPos];
|
||||
i2++;
|
||||
|
||||
currentChar = ch2;
|
||||
@@ -927,8 +927,8 @@ namespace Compress.Support.Compression.BZip2
|
||||
count++;
|
||||
if (count >= 4)
|
||||
{
|
||||
z = ll8[tPos];
|
||||
tPos = tt[tPos];
|
||||
z = ll8![tPos];
|
||||
tPos = tt![tPos];
|
||||
if (rNToGo == 0)
|
||||
{
|
||||
rNToGo = BZip2Constants.rNums[rTPos];
|
||||
@@ -982,8 +982,8 @@ namespace Compress.Support.Compression.BZip2
|
||||
count++;
|
||||
if (count >= 4)
|
||||
{
|
||||
z = ll8[tPos];
|
||||
tPos = tt[tPos];
|
||||
z = ll8![tPos];
|
||||
tPos = tt![tPos];
|
||||
currentState = NO_RAND_PART_C_STATE;
|
||||
j2 = 0;
|
||||
SetupNoRandPartC();
|
||||
|
||||
@@ -277,11 +277,11 @@ namespace Compress.Support.Compression.BZip2
|
||||
private char[] selector = new char[BZip2Constants.MAX_SELECTORS];
|
||||
private char[] selectorMtf = new char[BZip2Constants.MAX_SELECTORS];
|
||||
|
||||
private char[] block;
|
||||
private int[] quadrant;
|
||||
private int[] zptr;
|
||||
private short[] szptr;
|
||||
private int[] ftab;
|
||||
private char[]? block;
|
||||
private int[]? quadrant;
|
||||
private int[]? zptr;
|
||||
private short[]? szptr;
|
||||
private int[]? ftab;
|
||||
|
||||
private int nMTF;
|
||||
|
||||
@@ -385,17 +385,17 @@ namespace Compress.Support.Compression.BZip2
|
||||
{
|
||||
case 1:
|
||||
last++;
|
||||
block[last + 1] = (char)currentChar;
|
||||
block![last + 1] = (char)currentChar;
|
||||
break;
|
||||
case 2:
|
||||
last++;
|
||||
block[last + 1] = (char)currentChar;
|
||||
block![last + 1] = (char)currentChar;
|
||||
last++;
|
||||
block[last + 1] = (char)currentChar;
|
||||
break;
|
||||
case 3:
|
||||
last++;
|
||||
block[last + 1] = (char)currentChar;
|
||||
block![last + 1] = (char)currentChar;
|
||||
last++;
|
||||
block[last + 1] = (char)currentChar;
|
||||
last++;
|
||||
@@ -404,7 +404,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
default:
|
||||
inUse[runLength - 4] = true;
|
||||
last++;
|
||||
block[last + 1] = (char)currentChar;
|
||||
block![last + 1] = (char)currentChar;
|
||||
last++;
|
||||
block[last + 1] = (char)currentChar;
|
||||
last++;
|
||||
@@ -440,7 +440,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
disposed = true;
|
||||
base.Dispose();
|
||||
if (!leaveOpen)
|
||||
bsStream.Dispose();
|
||||
bsStream!.Dispose();
|
||||
bsStream = null;
|
||||
}
|
||||
}
|
||||
@@ -465,7 +465,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
bsStream.Flush();
|
||||
bsStream!.Flush();
|
||||
}
|
||||
|
||||
private int blockCRC, combinedCRC;
|
||||
@@ -606,7 +606,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
int ch = (bsBuff >> 24);
|
||||
try
|
||||
{
|
||||
bsStream.WriteByte((byte)ch); // write 8-bit
|
||||
bsStream!.WriteByte((byte)ch); // write 8-bit
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
@@ -625,7 +625,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
int ch = (bsBuff >> 24);
|
||||
try
|
||||
{
|
||||
bsStream.WriteByte((byte)ch); // write 8-bit
|
||||
bsStream!.WriteByte((byte)ch); // write 8-bit
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
@@ -744,9 +744,9 @@ namespace Compress.Support.Compression.BZip2
|
||||
}
|
||||
}
|
||||
|
||||
int[][] rfreq = CBZip2InputStream.InitIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE);
|
||||
int[] fave = new int[BZip2Constants.N_GROUPS];
|
||||
short[] cost = new short[BZip2Constants.N_GROUPS];
|
||||
int[][]? rfreq = CBZip2InputStream.InitIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE);
|
||||
int[]? fave = new int[BZip2Constants.N_GROUPS];
|
||||
short[]? cost = new short[BZip2Constants.N_GROUPS];
|
||||
/*
|
||||
Iterate up to N_ITERS times to improve the tables.
|
||||
*/
|
||||
@@ -797,7 +797,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
cost0 = cost1 = cost2 = cost3 = cost4 = cost5 = 0;
|
||||
for (i = gs; i <= ge; i++)
|
||||
{
|
||||
short icv = szptr[i];
|
||||
short icv = szptr![i];
|
||||
cost0 += (short)len[0][icv];
|
||||
cost1 += (short)len[1][icv];
|
||||
cost2 += (short)len[2][icv];
|
||||
@@ -816,7 +816,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
{
|
||||
for (i = gs; i <= ge; i++)
|
||||
{
|
||||
short icv = szptr[i];
|
||||
short icv = szptr![i];
|
||||
for (t = 0; t < nGroups; t++)
|
||||
{
|
||||
cost[t] += (short)len[t][icv];
|
||||
@@ -848,7 +848,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
*/
|
||||
for (i = gs; i <= ge; i++)
|
||||
{
|
||||
rfreq[bt][szptr[i]]++;
|
||||
rfreq[bt][szptr![i]]++;
|
||||
}
|
||||
|
||||
gs = ge + 1;
|
||||
@@ -1032,7 +1032,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
}
|
||||
for (i = gs; i <= ge; i++)
|
||||
{
|
||||
BsW(len[selector[selCtr]][szptr[i]],
|
||||
BsW(len[selector[selCtr]][szptr![i]],
|
||||
code[selector[selCtr]][szptr[i]]);
|
||||
}
|
||||
|
||||
@@ -1052,7 +1052,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
SendMTFValues();
|
||||
}
|
||||
|
||||
private Stream bsStream;
|
||||
private Stream? bsStream;
|
||||
private bool leaveOpen;
|
||||
|
||||
private void SimpleSort(int lo, int hi, int d)
|
||||
@@ -1085,7 +1085,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
{
|
||||
break;
|
||||
}
|
||||
v = zptr[i];
|
||||
v = zptr![i];
|
||||
j = i;
|
||||
while (FullGtU(zptr[j - h] + d, v + d))
|
||||
{
|
||||
@@ -1150,7 +1150,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
int temp = 0;
|
||||
while (n > 0)
|
||||
{
|
||||
temp = zptr[p1];
|
||||
temp = zptr![p1];
|
||||
zptr[p1] = zptr[p2];
|
||||
zptr[p2] = temp;
|
||||
p1++;
|
||||
@@ -1227,7 +1227,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
continue;
|
||||
}
|
||||
|
||||
med = Med3(block[zptr[lo] + d + 1],
|
||||
med = Med3(block![zptr![lo] + d + 1],
|
||||
block[zptr[hi] + d + 1],
|
||||
block[zptr[(lo + hi) >> 1] + d + 1]);
|
||||
|
||||
@@ -1345,14 +1345,14 @@ namespace Compress.Support.Compression.BZip2
|
||||
// if (verbosity >= 4) fprintf ( stderr, " sort initialise ...\n" );
|
||||
for (i = 0; i < BZip2Constants.NUM_OVERSHOOT_BYTES; i++)
|
||||
{
|
||||
block[last + i + 2] = block[(i % (last + 1)) + 1];
|
||||
block![last + i + 2] = block[(i % (last + 1)) + 1];
|
||||
}
|
||||
for (i = 0; i <= last + BZip2Constants.NUM_OVERSHOOT_BYTES; i++)
|
||||
{
|
||||
quadrant[i] = 0;
|
||||
quadrant![i] = 0;
|
||||
}
|
||||
|
||||
block[0] = (char)(block[last + 1]);
|
||||
block![0] = (char)(block[last + 1]);
|
||||
|
||||
if (last < 4000)
|
||||
{
|
||||
@@ -1362,7 +1362,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
*/
|
||||
for (i = 0; i <= last; i++)
|
||||
{
|
||||
zptr[i] = i;
|
||||
zptr![i] = i;
|
||||
}
|
||||
firstAttempt = false;
|
||||
workDone = workLimit = 0;
|
||||
@@ -1378,20 +1378,20 @@ namespace Compress.Support.Compression.BZip2
|
||||
|
||||
for (i = 0; i <= 65536; i++)
|
||||
{
|
||||
ftab[i] = 0;
|
||||
ftab![i] = 0;
|
||||
}
|
||||
|
||||
c1 = block[0];
|
||||
for (i = 0; i <= last; i++)
|
||||
{
|
||||
c2 = block[i + 1];
|
||||
ftab[(c1 << 8) + c2]++;
|
||||
ftab![(c1 << 8) + c2]++;
|
||||
c1 = c2;
|
||||
}
|
||||
|
||||
for (i = 1; i <= 65536; i++)
|
||||
{
|
||||
ftab[i] += ftab[i - 1];
|
||||
ftab![i] += ftab[i - 1];
|
||||
}
|
||||
|
||||
c1 = block[1];
|
||||
@@ -1400,13 +1400,13 @@ namespace Compress.Support.Compression.BZip2
|
||||
c2 = block[i + 2];
|
||||
j = (c1 << 8) + c2;
|
||||
c1 = c2;
|
||||
ftab[j]--;
|
||||
zptr[ftab[j]] = i;
|
||||
ftab![j]--;
|
||||
zptr![ftab[j]] = i;
|
||||
}
|
||||
|
||||
j = ((block[last + 1]) << 8) + (block[1]);
|
||||
ftab[j]--;
|
||||
zptr[ftab[j]] = last;
|
||||
ftab![j]--;
|
||||
zptr![ftab[j]] = last;
|
||||
|
||||
/*
|
||||
Now ftab contains the first loc of every small bucket.
|
||||
@@ -1513,7 +1513,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
{
|
||||
int a2update = zptr[bbStart + j];
|
||||
int qVal = (j >> shifts);
|
||||
quadrant[a2update] = qVal;
|
||||
quadrant![a2update] = qVal;
|
||||
if (a2update < BZip2Constants.NUM_OVERSHOOT_BYTES)
|
||||
{
|
||||
quadrant[a2update + last + 1] = qVal;
|
||||
@@ -1576,7 +1576,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
}
|
||||
}
|
||||
rNToGo--;
|
||||
block[i + 1] ^= (char)((rNToGo == 1) ? 1 : 0);
|
||||
block![i + 1] ^= (char)((rNToGo == 1) ? 1 : 0);
|
||||
// handle 16 bit signed numbers
|
||||
block[i + 1] &= (char)0xFF;
|
||||
|
||||
@@ -1607,7 +1607,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
origPtr = -1;
|
||||
for (i = 0; i <= last; i++)
|
||||
{
|
||||
if (zptr[i] == 0)
|
||||
if (zptr![i] == 0)
|
||||
{
|
||||
origPtr = i;
|
||||
break;
|
||||
@@ -1626,7 +1626,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
char c1, c2;
|
||||
int s1, s2;
|
||||
|
||||
c1 = block[i1 + 1];
|
||||
c1 = block![i1 + 1];
|
||||
c2 = block[i2 + 1];
|
||||
if (c1 != c2)
|
||||
{
|
||||
@@ -1690,7 +1690,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
{
|
||||
return (c1 > c2);
|
||||
}
|
||||
s1 = quadrant[i1];
|
||||
s1 = quadrant![i1];
|
||||
s2 = quadrant[i2];
|
||||
if (s1 != s2)
|
||||
{
|
||||
@@ -1833,7 +1833,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
{
|
||||
char ll_i;
|
||||
|
||||
ll_i = unseqToSeq[block[zptr[i]]];
|
||||
ll_i = unseqToSeq[block![zptr![i]]];
|
||||
|
||||
j = 0;
|
||||
tmp = yy[j];
|
||||
@@ -1860,12 +1860,12 @@ namespace Compress.Support.Compression.BZip2
|
||||
switch (zPend % 2)
|
||||
{
|
||||
case 0:
|
||||
szptr[wr] = (short)BZip2Constants.RUNA;
|
||||
szptr![wr] = (short)BZip2Constants.RUNA;
|
||||
wr++;
|
||||
mtfFreq[BZip2Constants.RUNA]++;
|
||||
break;
|
||||
case 1:
|
||||
szptr[wr] = (short)BZip2Constants.RUNB;
|
||||
szptr![wr] = (short)BZip2Constants.RUNB;
|
||||
wr++;
|
||||
mtfFreq[BZip2Constants.RUNB]++;
|
||||
break;
|
||||
@@ -1878,7 +1878,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
};
|
||||
zPend = 0;
|
||||
}
|
||||
szptr[wr] = (short)(j + 1);
|
||||
szptr![wr] = (short)(j + 1);
|
||||
wr++;
|
||||
mtfFreq[j + 1]++;
|
||||
}
|
||||
@@ -1892,12 +1892,12 @@ namespace Compress.Support.Compression.BZip2
|
||||
switch (zPend % 2)
|
||||
{
|
||||
case 0:
|
||||
szptr[wr] = (short)BZip2Constants.RUNA;
|
||||
szptr![wr] = (short)BZip2Constants.RUNA;
|
||||
wr++;
|
||||
mtfFreq[BZip2Constants.RUNA]++;
|
||||
break;
|
||||
case 1:
|
||||
szptr[wr] = (short)BZip2Constants.RUNB;
|
||||
szptr![wr] = (short)BZip2Constants.RUNB;
|
||||
wr++;
|
||||
mtfFreq[BZip2Constants.RUNB]++;
|
||||
break;
|
||||
@@ -1910,7 +1910,7 @@ namespace Compress.Support.Compression.BZip2
|
||||
}
|
||||
}
|
||||
|
||||
szptr[wr] = (short)EOB;
|
||||
szptr![wr] = (short)EOB;
|
||||
wr++;
|
||||
mtfFreq[EOB]++;
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
}
|
||||
|
||||
|
||||
private CompressFunc DeflateFunction;
|
||||
private CompressFunc? DeflateFunction;
|
||||
|
||||
private static readonly System.String[] _ErrorMessage = new System.String[]
|
||||
{
|
||||
@@ -197,9 +197,9 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
private static readonly int END_BLOCK = 256;
|
||||
|
||||
internal ZlibCodec _codec; // the zlib encoder/decoder
|
||||
internal ZlibCodec? _codec; // the zlib encoder/decoder
|
||||
internal int status; // as the name implies
|
||||
internal byte[] pending; // output still pending - waiting to be compressed
|
||||
internal byte[]? pending; // output still pending - waiting to be compressed
|
||||
internal int nextPending; // index of next pending byte to output to the stream
|
||||
internal int pendingCount; // number of bytes in the pending buffer
|
||||
|
||||
@@ -211,7 +211,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
internal int w_mask; // w_size - 1
|
||||
|
||||
//internal byte[] dictionary;
|
||||
internal byte[] window;
|
||||
internal byte[]? window;
|
||||
|
||||
// Sliding window. Input bytes are read into the second half of the window,
|
||||
// and move to the first half later to keep a dictionary of at least wSize
|
||||
@@ -225,12 +225,12 @@ namespace Compress.Support.Compression.Deflate
|
||||
// Actual size of window: 2*wSize, except when the user input buffer
|
||||
// is directly used as sliding window.
|
||||
|
||||
internal short[] prev;
|
||||
internal short[]? prev;
|
||||
// Link to older string with same hash index. To limit the size of this
|
||||
// array to 64K, this link is maintained only for the last 32K strings.
|
||||
// An index in this array is thus a window InStreamIndex modulo 32K.
|
||||
|
||||
internal short[] head; // Heads of the hash chains or NIL.
|
||||
internal short[]? head; // Heads of the hash chains or NIL.
|
||||
|
||||
internal int ins_h; // hash index of string to be inserted
|
||||
internal int hash_size; // number of elements in hash table
|
||||
@@ -248,7 +248,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
internal int block_start;
|
||||
|
||||
Config config;
|
||||
Config? config;
|
||||
internal int match_length; // length of best match
|
||||
internal int prev_match; // previous match
|
||||
internal int match_available; // set if previous match exists
|
||||
@@ -268,9 +268,9 @@ namespace Compress.Support.Compression.Deflate
|
||||
internal CompressionStrategy compressionStrategy; // favor or force Huffman coding
|
||||
|
||||
|
||||
internal short[] dyn_ltree; // literal and length tree
|
||||
internal short[] dyn_dtree; // distance tree
|
||||
internal short[] bl_tree; // Huffman tree for bit lengths
|
||||
internal short[]? dyn_ltree; // literal and length tree
|
||||
internal short[]? dyn_dtree; // distance tree
|
||||
internal short[]? bl_tree; // Huffman tree for bit lengths
|
||||
|
||||
internal Tree treeLiterals = new Tree(); // desc for literal tree
|
||||
internal Tree treeDistances = new Tree(); // desc for distance tree
|
||||
@@ -349,7 +349,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
window_size = 2 * w_size;
|
||||
|
||||
// clear the hash - workitem 9063
|
||||
Array.Clear(head, 0, hash_size);
|
||||
Array.Clear(head!, 0, hash_size);
|
||||
//for (int i = 0; i < hash_size; i++) head[i] = 0;
|
||||
|
||||
config = Config.Lookup(compressionLevel);
|
||||
@@ -366,13 +366,13 @@ namespace Compress.Support.Compression.Deflate
|
||||
// Initialize the tree data structures for a new zlib stream.
|
||||
private void _InitializeTreeData()
|
||||
{
|
||||
treeLiterals.dyn_tree = dyn_ltree;
|
||||
treeLiterals.dyn_tree = dyn_ltree!;
|
||||
treeLiterals.staticTree = StaticTree.Literals;
|
||||
|
||||
treeDistances.dyn_tree = dyn_dtree;
|
||||
treeDistances.dyn_tree = dyn_dtree!;
|
||||
treeDistances.staticTree = StaticTree.Distances;
|
||||
|
||||
treeBitLengths.dyn_tree = bl_tree;
|
||||
treeBitLengths.dyn_tree = bl_tree!;
|
||||
treeBitLengths.staticTree = StaticTree.BitLengths;
|
||||
|
||||
bi_buf = 0;
|
||||
@@ -387,13 +387,13 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
// Initialize the trees.
|
||||
for (int i = 0; i < InternalConstants.L_CODES; i++)
|
||||
dyn_ltree[i * 2] = 0;
|
||||
dyn_ltree![i * 2] = 0;
|
||||
for (int i = 0; i < InternalConstants.D_CODES; i++)
|
||||
dyn_dtree[i * 2] = 0;
|
||||
dyn_dtree![i * 2] = 0;
|
||||
for (int i = 0; i < InternalConstants.BL_CODES; i++)
|
||||
bl_tree[i * 2] = 0;
|
||||
bl_tree![i * 2] = 0;
|
||||
|
||||
dyn_ltree[END_BLOCK * 2] = 1;
|
||||
dyn_ltree![END_BLOCK * 2] = 1;
|
||||
opt_len = static_len = 0;
|
||||
last_lit = matches = 0;
|
||||
}
|
||||
@@ -460,21 +460,21 @@ namespace Compress.Support.Compression.Deflate
|
||||
}
|
||||
else if (count < min_count)
|
||||
{
|
||||
bl_tree[curlen * 2] = (short)(bl_tree[curlen * 2] + count);
|
||||
bl_tree![curlen * 2] = (short)(bl_tree[curlen * 2] + count);
|
||||
}
|
||||
else if (curlen != 0)
|
||||
{
|
||||
if (curlen != prevlen)
|
||||
bl_tree[curlen * 2]++;
|
||||
bl_tree[InternalConstants.REP_3_6 * 2]++;
|
||||
bl_tree![curlen * 2]++;
|
||||
bl_tree![InternalConstants.REP_3_6 * 2]++;
|
||||
}
|
||||
else if (count <= 10)
|
||||
{
|
||||
bl_tree[InternalConstants.REPZ_3_10 * 2]++;
|
||||
bl_tree![InternalConstants.REPZ_3_10 * 2]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
bl_tree[InternalConstants.REPZ_11_138 * 2]++;
|
||||
bl_tree![InternalConstants.REPZ_11_138 * 2]++;
|
||||
}
|
||||
count = 0; prevlen = curlen;
|
||||
if (nextlen == 0)
|
||||
@@ -499,8 +499,8 @@ namespace Compress.Support.Compression.Deflate
|
||||
int max_blindex; // index of last bit length code of non zero freq
|
||||
|
||||
// Determine the bit length frequencies for literal and distance trees
|
||||
scan_tree(dyn_ltree, treeLiterals.max_code);
|
||||
scan_tree(dyn_dtree, treeDistances.max_code);
|
||||
scan_tree(dyn_ltree!, treeLiterals.max_code);
|
||||
scan_tree(dyn_dtree!, treeDistances.max_code);
|
||||
|
||||
// Build the bit length tree:
|
||||
treeBitLengths.build_tree(this);
|
||||
@@ -512,7 +512,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
// 3 but the actual value used is 4.)
|
||||
for (max_blindex = InternalConstants.BL_CODES - 1; max_blindex >= 3; max_blindex--)
|
||||
{
|
||||
if (bl_tree[Tree.bl_order[max_blindex] * 2 + 1] != 0)
|
||||
if (bl_tree![Tree.bl_order[max_blindex] * 2 + 1] != 0)
|
||||
break;
|
||||
}
|
||||
// Update opt_len to include the bit length tree and counts
|
||||
@@ -534,10 +534,10 @@ namespace Compress.Support.Compression.Deflate
|
||||
send_bits(blcodes - 4, 4); // not -3 as stated in appnote.txt
|
||||
for (rank = 0; rank < blcodes; rank++)
|
||||
{
|
||||
send_bits(bl_tree[Tree.bl_order[rank] * 2 + 1], 3);
|
||||
send_bits(bl_tree![Tree.bl_order[rank] * 2 + 1], 3);
|
||||
}
|
||||
send_tree(dyn_ltree, lcodes - 1); // literal tree
|
||||
send_tree(dyn_dtree, dcodes - 1); // distance tree
|
||||
send_tree(dyn_ltree!, lcodes - 1); // literal tree
|
||||
send_tree(dyn_dtree!, dcodes - 1); // distance tree
|
||||
}
|
||||
|
||||
// Send a literal or distance tree in compressed form, using the codes in
|
||||
@@ -568,7 +568,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
do
|
||||
{
|
||||
send_code(curlen, bl_tree);
|
||||
send_code(curlen, bl_tree!);
|
||||
}
|
||||
while (--count != 0);
|
||||
}
|
||||
@@ -576,19 +576,19 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
if (curlen != prevlen)
|
||||
{
|
||||
send_code(curlen, bl_tree); count--;
|
||||
send_code(curlen, bl_tree!); count--;
|
||||
}
|
||||
send_code(InternalConstants.REP_3_6, bl_tree);
|
||||
send_code(InternalConstants.REP_3_6, bl_tree!);
|
||||
send_bits(count - 3, 2);
|
||||
}
|
||||
else if (count <= 10)
|
||||
{
|
||||
send_code(InternalConstants.REPZ_3_10, bl_tree);
|
||||
send_code(InternalConstants.REPZ_3_10, bl_tree!);
|
||||
send_bits(count - 3, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_code(InternalConstants.REPZ_11_138, bl_tree);
|
||||
send_code(InternalConstants.REPZ_11_138, bl_tree!);
|
||||
send_bits(count - 11, 7);
|
||||
}
|
||||
count = 0; prevlen = curlen;
|
||||
@@ -611,7 +611,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
// IN assertion: there is enough room in pending_buf.
|
||||
private void put_bytes(byte[] p, int start, int len)
|
||||
{
|
||||
Array.Copy(p, start, pending, pendingCount, len);
|
||||
Array.Copy(p, start, pending!, pendingCount, len);
|
||||
pendingCount += len;
|
||||
}
|
||||
|
||||
@@ -656,7 +656,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
bi_buf |= (short)((value << bi_valid) & 0xffff);
|
||||
//put_short(bi_buf);
|
||||
pending[pendingCount++] = (byte)bi_buf;
|
||||
pending![pendingCount++] = (byte)bi_buf;
|
||||
pending[pendingCount++] = (byte)(bi_buf >> 8);
|
||||
|
||||
|
||||
@@ -706,7 +706,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
// the current block must be flushed.
|
||||
internal bool _tr_tally(int dist, int lc)
|
||||
{
|
||||
pending[_distanceOffset + last_lit * 2] = unchecked((byte)((uint)dist >> 8));
|
||||
pending![_distanceOffset + last_lit * 2] = unchecked((byte)((uint)dist >> 8));
|
||||
pending[_distanceOffset + last_lit * 2 + 1] = unchecked((byte)dist);
|
||||
pending[_lengthOffset + last_lit] = unchecked((byte)lc);
|
||||
last_lit++;
|
||||
@@ -714,15 +714,15 @@ namespace Compress.Support.Compression.Deflate
|
||||
if (dist == 0)
|
||||
{
|
||||
// lc is the unmatched char
|
||||
dyn_ltree[lc * 2]++;
|
||||
dyn_ltree![lc * 2]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
matches++;
|
||||
// Here, lc is the match length - MIN_MATCH
|
||||
dist--; // dist = match distance - 1
|
||||
dyn_ltree[(Tree.LengthCode[lc] + InternalConstants.LITERALS + 1) * 2]++;
|
||||
dyn_dtree[Tree.DistanceCode(dist) * 2]++;
|
||||
dyn_ltree![(Tree.LengthCode[lc] + InternalConstants.LITERALS + 1) * 2]++;
|
||||
dyn_dtree![Tree.DistanceCode(dist) * 2]++;
|
||||
}
|
||||
|
||||
/* ************************************************************
|
||||
@@ -772,7 +772,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
do
|
||||
{
|
||||
int ix = _distanceOffset + lx * 2;
|
||||
distance = ((pending[ix] << 8) & 0xff00) |
|
||||
distance = ((pending![ix] << 8) & 0xff00) |
|
||||
(pending[ix + 1] & 0xff);
|
||||
lc = (pending[_lengthOffset + lx]) & 0xff;
|
||||
lx++;
|
||||
@@ -833,15 +833,15 @@ namespace Compress.Support.Compression.Deflate
|
||||
int bin_freq = 0;
|
||||
while (n < 7)
|
||||
{
|
||||
bin_freq += dyn_ltree[n * 2]; n++;
|
||||
bin_freq += dyn_ltree![n * 2]; n++;
|
||||
}
|
||||
while (n < 128)
|
||||
{
|
||||
ascii_freq += dyn_ltree[n * 2]; n++;
|
||||
ascii_freq += dyn_ltree![n * 2]; n++;
|
||||
}
|
||||
while (n < InternalConstants.LITERALS)
|
||||
{
|
||||
bin_freq += dyn_ltree[n * 2]; n++;
|
||||
bin_freq += dyn_ltree![n * 2]; n++;
|
||||
}
|
||||
data_type = (sbyte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII);
|
||||
}
|
||||
@@ -853,7 +853,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
if (bi_valid == 16)
|
||||
{
|
||||
pending[pendingCount++] = (byte)bi_buf;
|
||||
pending![pendingCount++] = (byte)bi_buf;
|
||||
pending[pendingCount++] = (byte)(bi_buf >> 8);
|
||||
bi_buf = 0;
|
||||
bi_valid = 0;
|
||||
@@ -861,7 +861,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
else if (bi_valid >= 8)
|
||||
{
|
||||
//put_byte((byte)bi_buf);
|
||||
pending[pendingCount++] = (byte)bi_buf;
|
||||
pending![pendingCount++] = (byte)bi_buf;
|
||||
bi_buf >>= 8;
|
||||
bi_valid -= 8;
|
||||
}
|
||||
@@ -872,13 +872,13 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
if (bi_valid > 8)
|
||||
{
|
||||
pending[pendingCount++] = (byte)bi_buf;
|
||||
pending![pendingCount++] = (byte)bi_buf;
|
||||
pending[pendingCount++] = (byte)(bi_buf >> 8);
|
||||
}
|
||||
else if (bi_valid > 0)
|
||||
{
|
||||
//put_byte((byte)bi_buf);
|
||||
pending[pendingCount++] = (byte)bi_buf;
|
||||
pending![pendingCount++] = (byte)bi_buf;
|
||||
}
|
||||
bi_buf = 0;
|
||||
bi_valid = 0;
|
||||
@@ -895,21 +895,21 @@ namespace Compress.Support.Compression.Deflate
|
||||
unchecked
|
||||
{
|
||||
//put_short((short)len);
|
||||
pending[pendingCount++] = (byte)len;
|
||||
pending![pendingCount++] = (byte)len;
|
||||
pending[pendingCount++] = (byte)(len >> 8);
|
||||
//put_short((short)~len);
|
||||
pending[pendingCount++] = (byte)~len;
|
||||
pending[pendingCount++] = (byte)(~len >> 8);
|
||||
}
|
||||
|
||||
put_bytes(window, buf, len);
|
||||
put_bytes(window!, buf, len);
|
||||
}
|
||||
|
||||
internal void flush_block_only(bool eof)
|
||||
{
|
||||
_tr_flush_block(block_start >= 0 ? block_start : -1, strstart - block_start, eof);
|
||||
block_start = strstart;
|
||||
_codec.flush_pending();
|
||||
_codec!.flush_pending();
|
||||
}
|
||||
|
||||
// Copy without compression as much as possible from the input stream, return
|
||||
@@ -927,7 +927,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
int max_block_size = 0xffff;
|
||||
int max_start;
|
||||
|
||||
if (max_block_size > pending.Length - 5)
|
||||
if (max_block_size > pending!.Length - 5)
|
||||
{
|
||||
max_block_size = pending.Length - 5;
|
||||
}
|
||||
@@ -957,7 +957,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
strstart = (int)max_start;
|
||||
|
||||
flush_block_only(false);
|
||||
if (_codec.AvailableBytesOut == 0)
|
||||
if (_codec!.AvailableBytesOut == 0)
|
||||
return BlockState.NeedMore;
|
||||
}
|
||||
|
||||
@@ -966,13 +966,13 @@ namespace Compress.Support.Compression.Deflate
|
||||
if (strstart - block_start >= w_size - MIN_LOOKAHEAD)
|
||||
{
|
||||
flush_block_only(false);
|
||||
if (_codec.AvailableBytesOut == 0)
|
||||
if (_codec!.AvailableBytesOut == 0)
|
||||
return BlockState.NeedMore;
|
||||
}
|
||||
}
|
||||
|
||||
flush_block_only(flush == FlushType.Finish);
|
||||
if (_codec.AvailableBytesOut == 0)
|
||||
if (_codec!.AvailableBytesOut == 0)
|
||||
return (flush == FlushType.Finish) ? BlockState.FinishStarted : BlockState.NeedMore;
|
||||
|
||||
return flush == FlushType.Finish ? BlockState.FinishDone : BlockState.BlockDone;
|
||||
@@ -1043,7 +1043,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
send_bits((DYN_TREES << 1) + (eof ? 1 : 0), 3);
|
||||
send_all_trees(treeLiterals.max_code + 1, treeDistances.max_code + 1, max_blindex + 1);
|
||||
send_compressed_block(dyn_ltree, dyn_dtree);
|
||||
send_compressed_block(dyn_ltree!, dyn_dtree!);
|
||||
}
|
||||
|
||||
// The above check is made mod 2^32, for files larger than 512 MB
|
||||
@@ -1091,7 +1091,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
}
|
||||
else if (strstart >= w_size + w_size - MIN_LOOKAHEAD)
|
||||
{
|
||||
Array.Copy(window, w_size, window, 0, w_size);
|
||||
Array.Copy(window!, w_size, window!, 0, w_size);
|
||||
match_start -= w_size;
|
||||
strstart -= w_size; // we now have strstart >= MAX_DIST
|
||||
block_start -= w_size;
|
||||
@@ -1106,7 +1106,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
p = n;
|
||||
do
|
||||
{
|
||||
m = (head[--p] & 0xffff);
|
||||
m = (head![--p] & 0xffff);
|
||||
head[p] = (short)((m >= w_size) ? (m - w_size) : 0);
|
||||
}
|
||||
while (--n != 0);
|
||||
@@ -1115,7 +1115,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
p = n;
|
||||
do
|
||||
{
|
||||
m = (prev[--p] & 0xffff);
|
||||
m = (prev![--p] & 0xffff);
|
||||
prev[p] = (short)((m >= w_size) ? (m - w_size) : 0);
|
||||
// If n is not on any hash chain, prev[n] is garbage but
|
||||
// its value will never be used.
|
||||
@@ -1124,7 +1124,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
more += w_size;
|
||||
}
|
||||
|
||||
if (_codec.AvailableBytesIn == 0)
|
||||
if (_codec!.AvailableBytesIn == 0)
|
||||
return;
|
||||
|
||||
// If there was no sliding:
|
||||
@@ -1138,13 +1138,13 @@ namespace Compress.Support.Compression.Deflate
|
||||
// Otherwise, window_size == 2*WSIZE so more >= 2.
|
||||
// If there was sliding, more >= WSIZE. So in all cases, more >= 2.
|
||||
|
||||
n = _codec.read_buf(window, strstart + lookahead, more);
|
||||
n = _codec.read_buf(window!, strstart + lookahead, more);
|
||||
lookahead += n;
|
||||
|
||||
// Initialize the hash value now that we have some input:
|
||||
if (lookahead >= MIN_MATCH)
|
||||
{
|
||||
ins_h = window[strstart] & 0xff;
|
||||
ins_h = window![strstart] & 0xff;
|
||||
ins_h = (((ins_h) << hash_shift) ^ (window[strstart + 1] & 0xff)) & hash_mask;
|
||||
}
|
||||
// If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
|
||||
@@ -1185,11 +1185,11 @@ namespace Compress.Support.Compression.Deflate
|
||||
// dictionary, and set hash_head to the head of the hash chain:
|
||||
if (lookahead >= MIN_MATCH)
|
||||
{
|
||||
ins_h = (((ins_h) << hash_shift) ^ (window[(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
|
||||
ins_h = (((ins_h) << hash_shift) ^ (window![(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
|
||||
|
||||
// prev[strstart&w_mask]=hash_head=head[ins_h];
|
||||
hash_head = (head[ins_h] & 0xffff);
|
||||
prev[strstart & w_mask] = head[ins_h];
|
||||
hash_head = (head![ins_h] & 0xffff);
|
||||
prev![strstart & w_mask] = head[ins_h];
|
||||
head[ins_h] = unchecked((short)strstart);
|
||||
}
|
||||
|
||||
@@ -1217,17 +1217,17 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
// Insert new strings in the hash table only if the match length
|
||||
// is not too large. This saves time but degrades compression.
|
||||
if (match_length <= config.MaxLazy && lookahead >= MIN_MATCH)
|
||||
if (match_length <= config!.MaxLazy && lookahead >= MIN_MATCH)
|
||||
{
|
||||
match_length--; // string at strstart already in hash table
|
||||
do
|
||||
{
|
||||
strstart++;
|
||||
|
||||
ins_h = ((ins_h << hash_shift) ^ (window[(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
|
||||
ins_h = ((ins_h << hash_shift) ^ (window![(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
|
||||
// prev[strstart&w_mask]=hash_head=head[ins_h];
|
||||
hash_head = (head[ins_h] & 0xffff);
|
||||
prev[strstart & w_mask] = head[ins_h];
|
||||
hash_head = (head![ins_h] & 0xffff);
|
||||
prev![strstart & w_mask] = head[ins_h];
|
||||
head[ins_h] = unchecked((short)strstart);
|
||||
|
||||
// strstart never exceeds WSIZE-MAX_MATCH, so there are
|
||||
@@ -1240,7 +1240,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
strstart += match_length;
|
||||
match_length = 0;
|
||||
ins_h = window[strstart] & 0xff;
|
||||
ins_h = window![strstart] & 0xff;
|
||||
|
||||
ins_h = (((ins_h) << hash_shift) ^ (window[strstart + 1] & 0xff)) & hash_mask;
|
||||
// If lookahead < MIN_MATCH, ins_h is garbage, but it does not
|
||||
@@ -1251,20 +1251,20 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
// No match, output a literal byte
|
||||
|
||||
bflush = _tr_tally(0, window[strstart] & 0xff);
|
||||
bflush = _tr_tally(0, window![strstart] & 0xff);
|
||||
lookahead--;
|
||||
strstart++;
|
||||
}
|
||||
if (bflush)
|
||||
{
|
||||
flush_block_only(false);
|
||||
if (_codec.AvailableBytesOut == 0)
|
||||
if (_codec!.AvailableBytesOut == 0)
|
||||
return BlockState.NeedMore;
|
||||
}
|
||||
}
|
||||
|
||||
flush_block_only(flush == FlushType.Finish);
|
||||
if (_codec.AvailableBytesOut == 0)
|
||||
if (_codec!.AvailableBytesOut == 0)
|
||||
{
|
||||
if (flush == FlushType.Finish)
|
||||
return BlockState.FinishStarted;
|
||||
@@ -1306,10 +1306,10 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
if (lookahead >= MIN_MATCH)
|
||||
{
|
||||
ins_h = (((ins_h) << hash_shift) ^ (window[(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
|
||||
ins_h = (((ins_h) << hash_shift) ^ (window![(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
|
||||
// prev[strstart&w_mask]=hash_head=head[ins_h];
|
||||
hash_head = (head[ins_h] & 0xffff);
|
||||
prev[strstart & w_mask] = head[ins_h];
|
||||
hash_head = (head![ins_h] & 0xffff);
|
||||
prev![strstart & w_mask] = head[ins_h];
|
||||
head[ins_h] = unchecked((short)strstart);
|
||||
}
|
||||
|
||||
@@ -1318,7 +1318,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
prev_match = match_start;
|
||||
match_length = MIN_MATCH - 1;
|
||||
|
||||
if (hash_head != 0 && prev_length < config.MaxLazy &&
|
||||
if (hash_head != 0 && prev_length < config!.MaxLazy &&
|
||||
((strstart - hash_head) & 0xffff) <= w_size - MIN_LOOKAHEAD)
|
||||
{
|
||||
// To simplify the code, we prevent matches with the string
|
||||
@@ -1362,10 +1362,10 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
if (++strstart <= max_insert)
|
||||
{
|
||||
ins_h = (((ins_h) << hash_shift) ^ (window[(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
|
||||
ins_h = (((ins_h) << hash_shift) ^ (window![(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
|
||||
//prev[strstart&w_mask]=hash_head=head[ins_h];
|
||||
hash_head = (head[ins_h] & 0xffff);
|
||||
prev[strstart & w_mask] = head[ins_h];
|
||||
hash_head = (head![ins_h] & 0xffff);
|
||||
prev![strstart & w_mask] = head[ins_h];
|
||||
head[ins_h] = unchecked((short)strstart);
|
||||
}
|
||||
}
|
||||
@@ -1377,7 +1377,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
if (bflush)
|
||||
{
|
||||
flush_block_only(false);
|
||||
if (_codec.AvailableBytesOut == 0)
|
||||
if (_codec!.AvailableBytesOut == 0)
|
||||
return BlockState.NeedMore;
|
||||
}
|
||||
}
|
||||
@@ -1388,7 +1388,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
// single literal. If there was a match but the current match
|
||||
// is longer, truncate the previous match to a single literal.
|
||||
|
||||
bflush = _tr_tally(0, window[strstart - 1] & 0xff);
|
||||
bflush = _tr_tally(0, window![strstart - 1] & 0xff);
|
||||
|
||||
if (bflush)
|
||||
{
|
||||
@@ -1396,7 +1396,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
}
|
||||
strstart++;
|
||||
lookahead--;
|
||||
if (_codec.AvailableBytesOut == 0)
|
||||
if (_codec!.AvailableBytesOut == 0)
|
||||
return BlockState.NeedMore;
|
||||
}
|
||||
else
|
||||
@@ -1412,12 +1412,12 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
if (match_available != 0)
|
||||
{
|
||||
bflush = _tr_tally(0, window[strstart - 1] & 0xff);
|
||||
bflush = _tr_tally(0, window![strstart - 1] & 0xff);
|
||||
match_available = 0;
|
||||
}
|
||||
flush_block_only(flush == FlushType.Finish);
|
||||
|
||||
if (_codec.AvailableBytesOut == 0)
|
||||
if (_codec!.AvailableBytesOut == 0)
|
||||
{
|
||||
if (flush == FlushType.Finish)
|
||||
return BlockState.FinishStarted;
|
||||
@@ -1431,7 +1431,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
internal int longest_match(int cur_match)
|
||||
{
|
||||
int chain_length = config.MaxChainLength; // max hash chain length
|
||||
int chain_length = config!.MaxChainLength; // max hash chain length
|
||||
int scan = strstart; // current string
|
||||
int match; // matched string
|
||||
int len; // length of current match
|
||||
@@ -1446,7 +1446,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
int wmask = w_mask;
|
||||
|
||||
int strend = strstart + MAX_MATCH;
|
||||
byte scan_end1 = window[scan + best_len - 1];
|
||||
byte scan_end1 = window![scan + best_len - 1];
|
||||
byte scan_end = window[scan + best_len];
|
||||
|
||||
// The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
|
||||
@@ -1509,7 +1509,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
scan_end = window[scan + best_len];
|
||||
}
|
||||
}
|
||||
while ((cur_match = (prev[cur_match & wmask] & 0xffff)) > limit && --chain_length != 0);
|
||||
while ((cur_match = (prev![cur_match & wmask] & 0xffff)) > limit && --chain_length != 0);
|
||||
|
||||
if (best_len <= lookahead)
|
||||
return best_len;
|
||||
@@ -1594,7 +1594,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
internal void Reset()
|
||||
{
|
||||
_codec.TotalBytesIn = _codec.TotalBytesOut = 0;
|
||||
_codec!.TotalBytesIn = _codec.TotalBytesOut = 0;
|
||||
_codec.Message = null;
|
||||
//strm.data_type = Z_UNKNOWN;
|
||||
|
||||
@@ -1632,7 +1632,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
private void SetDeflater()
|
||||
{
|
||||
switch (config.Flavor)
|
||||
switch (config!.Flavor)
|
||||
{
|
||||
case DeflateFlavor.Store:
|
||||
DeflateFunction = DeflateNone;
|
||||
@@ -1656,7 +1656,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
Config newConfig = Config.Lookup(level);
|
||||
|
||||
// change in the deflate flavor (Fast vs slow vs none)?
|
||||
if (newConfig.Flavor != config.Flavor && _codec.TotalBytesIn != 0)
|
||||
if (newConfig.Flavor != config!.Flavor && _codec!.TotalBytesIn != 0)
|
||||
{
|
||||
// Flush the last buffer:
|
||||
result = _codec.Deflate(FlushType.Partial);
|
||||
@@ -1682,7 +1682,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
if (dictionary == null || status != INIT_STATE)
|
||||
throw new ZlibException("Stream error.");
|
||||
|
||||
_codec._Adler32 = Adler.Adler32(_codec._Adler32, dictionary, 0, dictionary.Length);
|
||||
_codec!._Adler32 = Adler.Adler32(_codec._Adler32, dictionary, 0, dictionary.Length);
|
||||
|
||||
if (length < MIN_MATCH)
|
||||
return ZlibConstants.Z_OK;
|
||||
@@ -1691,7 +1691,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
length = w_size - MIN_LOOKAHEAD;
|
||||
index = dictionary.Length - length; // use the tail of the dictionary
|
||||
}
|
||||
Array.Copy(dictionary, index, window, 0, length);
|
||||
Array.Copy(dictionary, index, window!, 0, length);
|
||||
strstart = length;
|
||||
block_start = length;
|
||||
|
||||
@@ -1699,13 +1699,13 @@ namespace Compress.Support.Compression.Deflate
|
||||
// s->lookahead stays null, so s->ins_h will be recomputed at the next
|
||||
// call of fill_window.
|
||||
|
||||
ins_h = window[0] & 0xff;
|
||||
ins_h = window![0] & 0xff;
|
||||
ins_h = (((ins_h) << hash_shift) ^ (window[1] & 0xff)) & hash_mask;
|
||||
|
||||
for (int n = 0; n <= length - MIN_MATCH; n++)
|
||||
{
|
||||
ins_h = (((ins_h) << hash_shift) ^ (window[(n) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
|
||||
prev[n & w_mask] = head[ins_h];
|
||||
prev![n & w_mask] = head![ins_h];
|
||||
head[ins_h] = (short)n;
|
||||
}
|
||||
return ZlibConstants.Z_OK;
|
||||
@@ -1717,7 +1717,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
int old_flush;
|
||||
|
||||
if (_codec.OutputBuffer == null ||
|
||||
if (_codec!.OutputBuffer == null ||
|
||||
(_codec.InputBuffer == null && _codec.AvailableBytesIn != 0) ||
|
||||
(status == FINISH_STATE && flush != FlushType.Finish))
|
||||
{
|
||||
@@ -1750,7 +1750,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
//putShortMSB(header);
|
||||
unchecked
|
||||
{
|
||||
pending[pendingCount++] = (byte)(header >> 8);
|
||||
pending![pendingCount++] = (byte)(header >> 8);
|
||||
pending[pendingCount++] = (byte)header;
|
||||
}
|
||||
// Save the adler32 of the preset dictionary:
|
||||
@@ -1811,7 +1811,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
// Start a new block or continue the current one.
|
||||
if (_codec.AvailableBytesIn != 0 || lookahead != 0 || (flush != FlushType.None && status != FINISH_STATE))
|
||||
{
|
||||
BlockState bstate = DeflateFunction(flush);
|
||||
BlockState bstate = DeflateFunction!(flush);
|
||||
|
||||
if (bstate == BlockState.FinishStarted || bstate == BlockState.FinishDone)
|
||||
{
|
||||
@@ -1848,7 +1848,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
// clear hash (forget the history)
|
||||
for (int i = 0; i < hash_size; i++)
|
||||
head[i] = 0;
|
||||
head![i] = 0;
|
||||
}
|
||||
}
|
||||
_codec.flush_pending();
|
||||
@@ -1867,7 +1867,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
return ZlibConstants.Z_STREAM_END;
|
||||
|
||||
// Write the zlib trailer (adler32)
|
||||
pending[pendingCount++] = (byte)((_codec._Adler32 & 0xFF000000) >> 24);
|
||||
pending![pendingCount++] = (byte)((_codec._Adler32 & 0xFF000000) >> 24);
|
||||
pending[pendingCount++] = (byte)((_codec._Adler32 & 0x00FF0000) >> 16);
|
||||
pending[pendingCount++] = (byte)((_codec._Adler32 & 0x0000FF00) >> 8);
|
||||
pending[pendingCount++] = (byte)(_codec._Adler32 & 0x000000FF);
|
||||
|
||||
@@ -101,14 +101,14 @@ namespace Compress.Support.Compression.Deflate
|
||||
// If BMAX needs to be larger than 16, then h and x[] should be uLong.
|
||||
internal const int BMAX = 15; // maximum bit length of any code
|
||||
|
||||
internal int[] hn = null; // hufts used in space
|
||||
internal int[] v = null; // work area for huft_build
|
||||
internal int[] c = null; // bit length count table
|
||||
internal int[] r = null; // table entry for structure assignment
|
||||
internal int[] u = null; // table stack
|
||||
internal int[] x = null; // bit offsets, then code stack
|
||||
internal int[]? hn = null; // hufts used in space
|
||||
internal int[]? v = null; // work area for huft_build
|
||||
internal int[]? c = null; // bit length count table
|
||||
internal int[]? r = null; // table entry for structure assignment
|
||||
internal int[]? u = null; // table stack
|
||||
internal int[]? x = null; // bit offsets, then code stack
|
||||
|
||||
private int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
|
||||
private int huft_build(int[] b, int bindex, int n, int s, int[]? d, int[]? e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
|
||||
{
|
||||
// Given a list of code lengths and a maximum table size, make a set of
|
||||
// tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
|
||||
@@ -137,7 +137,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
p = 0; i = n;
|
||||
do
|
||||
{
|
||||
c[b[bindex + p]]++; p++; i--; // assume all entries <= BMAX
|
||||
c![b[bindex + p]]++; p++; i--; // assume all entries <= BMAX
|
||||
}
|
||||
while (i != 0);
|
||||
|
||||
@@ -186,7 +186,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
c[i] += y;
|
||||
|
||||
// Generate starting offsets into the value table for each length
|
||||
x[1] = j = 0;
|
||||
x![1] = j = 0;
|
||||
p = 1; xp = 2;
|
||||
while (--i != 0)
|
||||
{
|
||||
@@ -214,7 +214,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
p = 0; // grab values in bit order
|
||||
h = - 1; // no tables yet--level -1
|
||||
w = - l; // bits decoded == (l * h)
|
||||
u[0] = 0; // just to keep compilers happy
|
||||
u![0] = 0; // just to keep compilers happy
|
||||
q = 0; // ditto
|
||||
z = 0; // ditto
|
||||
|
||||
@@ -265,7 +265,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
if (h != 0)
|
||||
{
|
||||
x[h] = i; // save pattern for backing up
|
||||
r[0] = (sbyte) j; // bits in this table
|
||||
r![0] = (sbyte) j; // bits in this table
|
||||
r[1] = (sbyte) l; // bits to dump before this table
|
||||
j = SharedUtils.URShift(i, (w - l));
|
||||
r[2] = (int) (q - u[h - 1] - j); // offset to this table
|
||||
@@ -278,7 +278,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
}
|
||||
|
||||
// set up table entry in r
|
||||
r[1] = (sbyte) (k - w);
|
||||
r![1] = (sbyte) (k - w);
|
||||
if (p >= n)
|
||||
{
|
||||
r[0] = 128 + 64; // out of values--invalid code
|
||||
@@ -290,8 +290,8 @@ namespace Compress.Support.Compression.Deflate
|
||||
}
|
||||
else
|
||||
{
|
||||
r[0] = (sbyte) (e[v[p] - s] + 16 + 64); // non-simple--look up in lists
|
||||
r[2] = d[v[p++] - s];
|
||||
r[0] = (sbyte) (e![v[p] - s] + 16 + 64); // non-simple--look up in lists
|
||||
r[2] = d![v[p++] - s];
|
||||
}
|
||||
|
||||
// fill code-like entries with r
|
||||
@@ -326,8 +326,8 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
int result;
|
||||
initWorkArea(19);
|
||||
hn[0] = 0;
|
||||
result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
|
||||
hn![0] = 0;
|
||||
result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v!);
|
||||
|
||||
if (result == Z_DATA_ERROR)
|
||||
{
|
||||
@@ -347,8 +347,8 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
// build literal/length tree
|
||||
initWorkArea(288);
|
||||
hn[0] = 0;
|
||||
result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
|
||||
hn![0] = 0;
|
||||
result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v!);
|
||||
if (result != Z_OK || bl[0] == 0)
|
||||
{
|
||||
if (result == Z_DATA_ERROR)
|
||||
@@ -365,7 +365,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
// build distance tree
|
||||
initWorkArea(288);
|
||||
result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
|
||||
result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v!);
|
||||
|
||||
if (result != Z_OK || (bd[0] == 0 && nl > 257))
|
||||
{
|
||||
@@ -411,19 +411,19 @@ namespace Compress.Support.Compression.Deflate
|
||||
}
|
||||
else
|
||||
{
|
||||
if (v.Length < vsize)
|
||||
if (v!.Length < vsize)
|
||||
{
|
||||
v = new int[vsize];
|
||||
}
|
||||
Array.Clear(v,0,vsize);
|
||||
Array.Clear(c,0,BMAX+1);
|
||||
r[0]=0; r[1]=0; r[2]=0;
|
||||
Array.Clear(c!,0,BMAX+1);
|
||||
r![0]=0; r[1]=0; r[2]=0;
|
||||
// for(int i=0; i<BMAX; i++){u[i]=0;}
|
||||
//Array.Copy(c, 0, u, 0, BMAX);
|
||||
Array.Clear(u,0,BMAX);
|
||||
Array.Clear(u!,0,BMAX);
|
||||
// for(int i=0; i<BMAX+1; i++){x[i]=0;}
|
||||
//Array.Copy(c, 0, x, 0, BMAX + 1);
|
||||
Array.Clear(x,0,BMAX+1);
|
||||
Array.Clear(x!,0,BMAX+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
internal int table; // table lengths (14 bits)
|
||||
internal int index; // index into blens (or border)
|
||||
internal int[] blens; // bit lengths of codes
|
||||
internal int[]? blens; // bit lengths of codes
|
||||
internal int[] bb = new int[1]; // bit length tree depth
|
||||
internal int[] tb = new int[1]; // bit length decoding tree
|
||||
|
||||
@@ -107,17 +107,17 @@ namespace Compress.Support.Compression.Deflate
|
||||
// mode independent information
|
||||
internal int bitk; // bits in bit buffer
|
||||
internal int bitb; // bit buffer
|
||||
internal int[] hufts; // single malloc for tree space
|
||||
internal byte[] window; // sliding window
|
||||
internal int[]? hufts; // single malloc for tree space
|
||||
internal byte[]? window; // sliding window
|
||||
internal int end; // one byte after sliding window
|
||||
internal int readAt; // window read pointer
|
||||
internal int writeAt; // window write pointer
|
||||
internal System.Object checkfn; // check function
|
||||
internal System.Object? checkfn; // check function
|
||||
internal uint check; // check on output
|
||||
|
||||
internal InfTree inftree = new InfTree();
|
||||
|
||||
internal InflateBlocks(ZlibCodec codec, System.Object checkfn, int w)
|
||||
internal InflateBlocks(ZlibCodec codec, System.Object? checkfn, int w)
|
||||
{
|
||||
_codec = codec;
|
||||
hufts = new int[MANY * 3];
|
||||
@@ -317,7 +317,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
t = n;
|
||||
if (t > m)
|
||||
t = m;
|
||||
Array.Copy(_codec.InputBuffer, p, window, q, t);
|
||||
Array.Copy(_codec.InputBuffer, p, window!, q, t);
|
||||
p += t; n -= t;
|
||||
q += t; m -= t;
|
||||
if ((left -= t) != 0)
|
||||
@@ -408,18 +408,18 @@ namespace Compress.Support.Compression.Deflate
|
||||
k += 8;
|
||||
}
|
||||
|
||||
blens[border[index++]] = b & 7;
|
||||
blens![border[index++]] = b & 7;
|
||||
|
||||
b >>= 3; k -= 3;
|
||||
}
|
||||
|
||||
while (index < 19)
|
||||
{
|
||||
blens[border[index++]] = 0;
|
||||
blens![border[index++]] = 0;
|
||||
}
|
||||
|
||||
bb[0] = 7;
|
||||
t = inftree.inflate_trees_bits(blens, bb, tb, hufts, _codec);
|
||||
t = inftree.inflate_trees_bits(blens!, bb, tb, hufts!, _codec);
|
||||
if (t != ZlibConstants.Z_OK)
|
||||
{
|
||||
r = t;
|
||||
@@ -475,13 +475,13 @@ namespace Compress.Support.Compression.Deflate
|
||||
k += 8;
|
||||
}
|
||||
|
||||
t = hufts[(tb[0] + (b & InternalInflateConstants.InflateMask[t])) * 3 + 1];
|
||||
t = hufts![(tb[0] + (b & InternalInflateConstants.InflateMask[t])) * 3 + 1];
|
||||
c = hufts[(tb[0] + (b & InternalInflateConstants.InflateMask[t])) * 3 + 2];
|
||||
|
||||
if (c < 16)
|
||||
{
|
||||
b >>= t; k -= t;
|
||||
blens[index++] = c;
|
||||
blens![index++] = c;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -533,10 +533,10 @@ namespace Compress.Support.Compression.Deflate
|
||||
return Flush(r);
|
||||
}
|
||||
|
||||
c = (c == 16) ? blens[i-1] : 0;
|
||||
c = (c == 16) ? blens![i-1] : 0;
|
||||
do
|
||||
{
|
||||
blens[i++] = c;
|
||||
blens![i++] = c;
|
||||
}
|
||||
while (--j != 0);
|
||||
index = i;
|
||||
@@ -551,7 +551,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
int[] td = new int[1];
|
||||
|
||||
t = table;
|
||||
t = inftree.inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), blens, bl, bd, tl, td, hufts, _codec);
|
||||
t = inftree.inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), blens!, bl, bd, tl, td, hufts!, _codec);
|
||||
|
||||
if (t != ZlibConstants.Z_OK)
|
||||
{
|
||||
@@ -569,7 +569,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
writeAt = q;
|
||||
return Flush(r);
|
||||
}
|
||||
codes.Init(bl[0], bd[0], hufts, tl[0], hufts, td[0]);
|
||||
codes.Init(bl[0], bd[0], hufts!, tl[0], hufts!, td[0]);
|
||||
}
|
||||
mode = InflateBlockMode.CODES;
|
||||
goto case InflateBlockMode.CODES;
|
||||
@@ -663,7 +663,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
internal void SetDictionary(byte[] d, int start, int n)
|
||||
{
|
||||
Array.Copy(d, start, window, 0, n);
|
||||
Array.Copy(d, start, window!, 0, n);
|
||||
readAt = writeAt = n;
|
||||
}
|
||||
|
||||
@@ -715,7 +715,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
_codec._Adler32 = check = Adler.Adler32(check, window, readAt, nBytes);
|
||||
|
||||
// copy as far as end of window
|
||||
Array.Copy(window, readAt, _codec.OutputBuffer, _codec.NextOut, nBytes);
|
||||
Array.Copy(window!, readAt, _codec.OutputBuffer, _codec.NextOut, nBytes);
|
||||
_codec.NextOut += nBytes;
|
||||
readAt += nBytes;
|
||||
|
||||
@@ -768,7 +768,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
// mode dependent information
|
||||
internal int len;
|
||||
|
||||
internal int[] tree; // pointer into tree
|
||||
internal int[]? tree; // pointer into tree
|
||||
internal int tree_index = 0;
|
||||
internal int need; // bits needed
|
||||
|
||||
@@ -780,9 +780,9 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
internal byte lbits; // ltree bits decoded per branch
|
||||
internal byte dbits; // dtree bits decoder per branch
|
||||
internal int[] ltree; // literal/length/eob tree
|
||||
internal int[]? ltree; // literal/length/eob tree
|
||||
internal int ltree_index; // literal/length/eob tree
|
||||
internal int[] dtree; // distance tree
|
||||
internal int[]? dtree; // distance tree
|
||||
internal int dtree_index; // distance tree
|
||||
|
||||
internal InflateCodes()
|
||||
@@ -837,7 +837,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
z.TotalBytesIn += p - z.NextIn;
|
||||
z.NextIn = p;
|
||||
blocks.writeAt = q;
|
||||
r = InflateFast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, blocks, z);
|
||||
r = InflateFast(lbits, dbits, ltree!, ltree_index, dtree!, dtree_index, blocks, z);
|
||||
|
||||
p = z.NextIn;
|
||||
n = z.AvailableBytesIn;
|
||||
@@ -881,7 +881,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
tindex = (tree_index + (b & InternalInflateConstants.InflateMask[j])) * 3;
|
||||
|
||||
b >>= (tree[tindex + 1]);
|
||||
b >>= (tree![tindex + 1]);
|
||||
k -= (tree[tindex + 1]);
|
||||
|
||||
e = tree[tindex];
|
||||
@@ -975,7 +975,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
tindex = (tree_index + (b & InternalInflateConstants.InflateMask[j])) * 3;
|
||||
|
||||
b >>= tree[tindex + 1];
|
||||
b >>= tree![tindex + 1];
|
||||
k -= tree[tindex + 1];
|
||||
|
||||
e = (tree[tindex]);
|
||||
@@ -1067,7 +1067,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
}
|
||||
}
|
||||
|
||||
blocks.window[q++] = blocks.window[f++]; m--;
|
||||
blocks.window![q++] = blocks.window[f++]; m--;
|
||||
|
||||
if (f == blocks.end)
|
||||
f = 0;
|
||||
@@ -1103,7 +1103,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
}
|
||||
r = ZlibConstants.Z_OK;
|
||||
|
||||
blocks.window[q++] = (byte)lit; m--;
|
||||
blocks.window![q++] = (byte)lit; m--;
|
||||
|
||||
mode = START;
|
||||
break;
|
||||
@@ -1211,7 +1211,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
b >>= (tp[tp_index_t_3 + 1]); k -= (tp[tp_index_t_3 + 1]);
|
||||
|
||||
s.window[q++] = (byte)tp[tp_index_t_3 + 2];
|
||||
s.window![q++] = (byte)tp[tp_index_t_3 + 2];
|
||||
m--;
|
||||
continue;
|
||||
}
|
||||
@@ -1270,13 +1270,13 @@ namespace Compress.Support.Compression.Deflate
|
||||
r = q - d;
|
||||
if (q - r > 0 && 2 > (q - r))
|
||||
{
|
||||
s.window[q++] = s.window[r++]; // minimum count is three,
|
||||
s.window![q++] = s.window[r++]; // minimum count is three,
|
||||
s.window[q++] = s.window[r++]; // so unroll loop a little
|
||||
c -= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
Array.Copy(s.window, r, s.window, q, 2);
|
||||
Array.Copy(s.window!, r, s.window!, q, 2);
|
||||
q += 2; r += 2; c -= 2;
|
||||
}
|
||||
}
|
||||
@@ -1298,13 +1298,13 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
do
|
||||
{
|
||||
s.window[q++] = s.window[r++];
|
||||
s.window![q++] = s.window[r++];
|
||||
}
|
||||
while (--e != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Array.Copy(s.window, r, s.window, q, e);
|
||||
Array.Copy(s.window!, r, s.window!, q, e);
|
||||
q += e; r += e; e = 0;
|
||||
}
|
||||
r = 0; // copy rest from start of window
|
||||
@@ -1316,13 +1316,13 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
do
|
||||
{
|
||||
s.window[q++] = s.window[r++];
|
||||
s.window![q++] = s.window[r++];
|
||||
}
|
||||
while (--c != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Array.Copy(s.window, r, s.window, q, c);
|
||||
Array.Copy(s.window!, r, s.window!, q, c);
|
||||
q += c; r += c; c = 0;
|
||||
}
|
||||
break;
|
||||
@@ -1359,7 +1359,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
if ((e = tp[tp_index_t_3]) == 0)
|
||||
{
|
||||
b >>= (tp[tp_index_t_3 + 1]); k -= (tp[tp_index_t_3 + 1]);
|
||||
s.window[q++] = (byte)tp[tp_index_t_3 + 2];
|
||||
s.window![q++] = (byte)tp[tp_index_t_3 + 2];
|
||||
m--;
|
||||
break;
|
||||
}
|
||||
@@ -1429,7 +1429,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
}
|
||||
|
||||
private InflateManagerMode mode; // current inflate mode
|
||||
internal ZlibCodec _codec; // pointer back to this zlib stream
|
||||
internal ZlibCodec? _codec; // pointer back to this zlib stream
|
||||
|
||||
// mode dependent information
|
||||
internal int method; // if FLAGS, method byte
|
||||
@@ -1451,7 +1451,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
}
|
||||
internal int wbits; // log2(window size) (8..15, defaults to 15)
|
||||
|
||||
internal InflateBlocks blocks; // current inflate_blocks state
|
||||
internal InflateBlocks? blocks; // current inflate_blocks state
|
||||
|
||||
public InflateManager() { }
|
||||
|
||||
@@ -1462,10 +1462,10 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
internal int Reset()
|
||||
{
|
||||
_codec.TotalBytesIn = _codec.TotalBytesOut = 0;
|
||||
_codec!.TotalBytesIn = _codec.TotalBytesOut = 0;
|
||||
_codec.Message = null;
|
||||
mode = HandleRfc1950HeaderBytes ? InflateManagerMode.METHOD : InflateManagerMode.BLOCKS;
|
||||
blocks.Reset();
|
||||
blocks!.Reset();
|
||||
return ZlibConstants.Z_OK;
|
||||
}
|
||||
|
||||
@@ -1515,7 +1515,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
int b;
|
||||
|
||||
if (_codec.InputBuffer == null)
|
||||
if (_codec!.InputBuffer == null)
|
||||
throw new ZlibException("InputBuffer is null. ");
|
||||
|
||||
// int f = (flush == FlushType.Finish)
|
||||
@@ -1620,7 +1620,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
|
||||
case InflateManagerMode.BLOCKS:
|
||||
r = blocks.Process(r);
|
||||
r = blocks!.Process(r);
|
||||
if (r == ZlibConstants.Z_DATA_ERROR)
|
||||
{
|
||||
mode = InflateManagerMode.BAD;
|
||||
@@ -1706,7 +1706,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
if (mode != InflateManagerMode.DICT0)
|
||||
throw new ZlibException("Stream error.");
|
||||
|
||||
if (Adler.Adler32(1, dictionary, 0, dictionary.Length) != _codec._Adler32)
|
||||
if (Adler.Adler32(1, dictionary, 0, dictionary.Length) != _codec!._Adler32)
|
||||
{
|
||||
return ZlibConstants.Z_DATA_ERROR;
|
||||
}
|
||||
@@ -1718,7 +1718,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
length = (1 << wbits) - 1;
|
||||
index = dictionary.Length - length;
|
||||
}
|
||||
blocks.SetDictionary(dictionary, index, length);
|
||||
blocks!.SetDictionary(dictionary, index, length);
|
||||
mode = InflateManagerMode.BLOCKS;
|
||||
return ZlibConstants.Z_OK;
|
||||
}
|
||||
@@ -1739,7 +1739,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
mode = InflateManagerMode.BAD;
|
||||
marker = 0;
|
||||
}
|
||||
if ((n = _codec.AvailableBytesIn) == 0)
|
||||
if ((n = _codec!.AvailableBytesIn) == 0)
|
||||
return ZlibConstants.Z_BUF_ERROR;
|
||||
p = _codec.NextIn;
|
||||
m = marker;
|
||||
@@ -1791,7 +1791,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
// waiting for these length bytes.
|
||||
internal int SyncPoint(ZlibCodec z)
|
||||
{
|
||||
return blocks.SyncPoint();
|
||||
return blocks!.SyncPoint();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,9 +180,9 @@ namespace Compress.Support.Compression.Deflate
|
||||
: _dist_code[256 + SharedUtils.URShift(dist, 7)];
|
||||
}
|
||||
|
||||
internal short[] dyn_tree; // the dynamic tree
|
||||
internal short[]? dyn_tree; // the dynamic tree
|
||||
internal int max_code; // largest code with non zero frequency
|
||||
internal StaticTree staticTree; // the corresponding static tree
|
||||
internal StaticTree? staticTree; // the corresponding static tree
|
||||
|
||||
// Compute the optimal bit lengths for a tree and update the total bit length
|
||||
// for the current block.
|
||||
@@ -194,9 +194,9 @@ namespace Compress.Support.Compression.Deflate
|
||||
// not null.
|
||||
internal void gen_bitlen(DeflateManager s)
|
||||
{
|
||||
short[] tree = dyn_tree;
|
||||
short[] stree = staticTree.treeCodes;
|
||||
int[] extra = staticTree.extraBits;
|
||||
short[] tree = dyn_tree!;
|
||||
short[]? stree = staticTree!.treeCodes;
|
||||
int[]? extra = staticTree.extraBits;
|
||||
int base_Renamed = staticTree.extraBase;
|
||||
int max_length = staticTree.maxLength;
|
||||
int h; // heap index
|
||||
@@ -230,7 +230,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
s.bl_count[bits]++;
|
||||
xbits = 0;
|
||||
if (n >= base_Renamed)
|
||||
xbits = extra[n - base_Renamed];
|
||||
xbits = extra![n - base_Renamed];
|
||||
f = tree[n * 2];
|
||||
s.opt_len += f * (bits + xbits);
|
||||
if (stree != null)
|
||||
@@ -281,8 +281,8 @@ namespace Compress.Support.Compression.Deflate
|
||||
// also updated if stree is not null. The field max_code is set.
|
||||
internal void build_tree(DeflateManager s)
|
||||
{
|
||||
short[] tree = dyn_tree;
|
||||
short[] stree = staticTree.treeCodes;
|
||||
short[] tree = dyn_tree!;
|
||||
short[]? stree = staticTree!.treeCodes;
|
||||
int elems = staticTree.elems;
|
||||
int n, m; // iterate over heap elements
|
||||
int max_code = -1; // largest code with non zero frequency
|
||||
|
||||
@@ -371,13 +371,13 @@ namespace Compress.Support.Compression.Deflate
|
||||
internal static readonly StaticTree Distances;
|
||||
internal static readonly StaticTree BitLengths;
|
||||
|
||||
internal short[] treeCodes; // static tree or null
|
||||
internal int[] extraBits; // extra bits for each code or null
|
||||
internal short[]? treeCodes; // static tree or null
|
||||
internal int[]? extraBits; // extra bits for each code or null
|
||||
internal int extraBase; // base index for extra_bits
|
||||
internal int elems; // max number of elements in the tree
|
||||
internal int maxLength; // max bit length for the codes
|
||||
|
||||
private StaticTree(short[] treeCodes, int[] extraBits, int extraBase, int elems, int maxLength)
|
||||
private StaticTree(short[]? treeCodes, int[] extraBits, int extraBase, int elems, int maxLength)
|
||||
{
|
||||
this.treeCodes = treeCodes;
|
||||
this.extraBits = extraBits;
|
||||
@@ -428,7 +428,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
/// adler = Adler.Adler32(adler, buffer, index, length);
|
||||
/// </code>
|
||||
/// </example>
|
||||
public static uint Adler32(uint adler, byte[] buf, int index, int len)
|
||||
public static uint Adler32(uint adler, byte[]? buf, int index, int len)
|
||||
{
|
||||
if (buf == null)
|
||||
return 1;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
public class ZlibBaseStream : System.IO.Stream
|
||||
{
|
||||
protected internal ZlibCodec _z = null; // deferred init... new ZlibCodec();
|
||||
protected internal ZlibCodec? _z = null; // deferred init... new ZlibCodec();
|
||||
|
||||
protected internal StreamMode _streamMode = StreamMode.Undefined;
|
||||
protected internal FlushType _flushMode;
|
||||
@@ -42,17 +42,17 @@ namespace Compress.Support.Compression.Deflate
|
||||
protected internal CompressionMode _compressionMode;
|
||||
protected internal CompressionLevel _level;
|
||||
protected internal bool _leaveOpen;
|
||||
protected internal byte[] _workingBuffer;
|
||||
protected internal byte[]? _workingBuffer;
|
||||
protected internal int _bufferSize = ZlibConstants.WorkingBufferSizeDefault;
|
||||
protected internal byte[] _buf1 = new byte[1];
|
||||
|
||||
protected internal System.IO.Stream _stream;
|
||||
protected internal System.IO.Stream? _stream;
|
||||
protected internal CompressionStrategy Strategy = CompressionStrategy.Default;
|
||||
|
||||
// workitem 7159
|
||||
CRC crc;
|
||||
protected internal string _GzipFileName;
|
||||
protected internal string _GzipComment;
|
||||
CRC? crc;
|
||||
protected internal string? _GzipFileName;
|
||||
protected internal string? _GzipComment;
|
||||
protected internal DateTime _GzipMtime;
|
||||
protected internal int _gzipHeaderByteCount;
|
||||
|
||||
@@ -141,14 +141,14 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
// first reference of z property will initialize the private var _z
|
||||
z.InputBuffer = buffer;
|
||||
_z.NextIn = offset;
|
||||
_z!.NextIn = offset;
|
||||
_z.AvailableBytesIn = count;
|
||||
bool done = false;
|
||||
do
|
||||
{
|
||||
_z.OutputBuffer = workingBuffer;
|
||||
_z.NextOut = 0;
|
||||
_z.AvailableBytesOut = _workingBuffer.Length;
|
||||
_z.AvailableBytesOut = _workingBuffer!.Length;
|
||||
int rc = (_wantCompress)
|
||||
? _z.Deflate(_flushMode)
|
||||
: _z.Inflate(_flushMode);
|
||||
@@ -156,7 +156,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
throw new ZlibException((_wantCompress ? "de" : "in") + "flating: " + _z.Message);
|
||||
|
||||
//if (_workingBuffer.Length - _z.AvailableBytesOut > 0)
|
||||
_stream.Write(_workingBuffer, 0, _workingBuffer.Length - _z.AvailableBytesOut);
|
||||
_stream!.Write(_workingBuffer, 0, _workingBuffer.Length - _z.AvailableBytesOut);
|
||||
|
||||
done = _z.AvailableBytesIn == 0 && _z.AvailableBytesOut != 0;
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
_z.OutputBuffer = workingBuffer;
|
||||
_z.NextOut = 0;
|
||||
_z.AvailableBytesOut = _workingBuffer.Length;
|
||||
_z.AvailableBytesOut = _workingBuffer!.Length;
|
||||
int rc = (_wantCompress)
|
||||
? _z.Deflate(FlushType.Finish)
|
||||
: _z.Inflate(FlushType.Finish);
|
||||
@@ -197,7 +197,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
if (_workingBuffer.Length - _z.AvailableBytesOut > 0)
|
||||
{
|
||||
_stream.Write(_workingBuffer, 0, _workingBuffer.Length - _z.AvailableBytesOut);
|
||||
_stream!.Write(_workingBuffer, 0, _workingBuffer.Length - _z.AvailableBytesOut);
|
||||
}
|
||||
|
||||
done = _z.AvailableBytesIn == 0 && _z.AvailableBytesOut != 0;
|
||||
@@ -216,8 +216,8 @@ namespace Compress.Support.Compression.Deflate
|
||||
if (_wantCompress)
|
||||
{
|
||||
// Emit the GZIP trailer: CRC32 and size mod 2^32
|
||||
int c1 = crc.Crc32Result;
|
||||
_stream.Write(BitConverter.GetBytes(c1), 0, 4);
|
||||
int c1 = crc!.Crc32Result;
|
||||
_stream!.Write(BitConverter.GetBytes(c1), 0, 4);
|
||||
int c2 = (Int32)(crc.TotalBytesRead & 0x00000000FFFFFFFF);
|
||||
_stream.Write(BitConverter.GetBytes(c2), 0, 4);
|
||||
}
|
||||
@@ -248,7 +248,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
// Make sure we have read to the end of the stream
|
||||
Array.Copy(_z.InputBuffer, _z.NextIn, trailer, 0, _z.AvailableBytesIn);
|
||||
int bytesNeeded = 8 - _z.AvailableBytesIn;
|
||||
int bytesRead = _stream.Read(trailer,
|
||||
int bytesRead = _stream!.Read(trailer,
|
||||
_z.AvailableBytesIn,
|
||||
bytesNeeded);
|
||||
if (bytesNeeded != bytesRead)
|
||||
@@ -263,7 +263,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
}
|
||||
|
||||
Int32 crc32_expected = BitConverter.ToInt32(trailer, 0);
|
||||
Int32 crc32_actual = crc.Crc32Result;
|
||||
Int32 crc32_actual = crc!.Crc32Result;
|
||||
Int32 isize_expected = BitConverter.ToInt32(trailer, 4);
|
||||
Int32 isize_actual = (Int32)(_z.TotalBytesOut & 0x00000000FFFFFFFF);
|
||||
|
||||
@@ -289,11 +289,11 @@ namespace Compress.Support.Compression.Deflate
|
||||
return;
|
||||
if (_wantCompress)
|
||||
{
|
||||
_z.EndDeflate();
|
||||
_z!.EndDeflate();
|
||||
}
|
||||
else
|
||||
{
|
||||
_z.EndInflate();
|
||||
_z!.EndInflate();
|
||||
}
|
||||
_z = null;
|
||||
}
|
||||
@@ -316,7 +316,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
_stream.Flush();
|
||||
_stream!.Flush();
|
||||
}
|
||||
|
||||
public override System.Int64 Seek(System.Int64 offset, System.IO.SeekOrigin origin)
|
||||
@@ -326,7 +326,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
}
|
||||
public override void SetLength(System.Int64 value)
|
||||
{
|
||||
_stream.SetLength(value);
|
||||
_stream!.SetLength(value);
|
||||
}
|
||||
|
||||
private bool nomoreinput = false;
|
||||
@@ -340,7 +340,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
do
|
||||
{
|
||||
// workitem 7740
|
||||
int n = _stream.Read(_buf1, 0, 1);
|
||||
int n = _stream!.Read(_buf1, 0, 1);
|
||||
if (n != 1)
|
||||
throw new ZlibException("Unexpected EOF reading GZIP header.");
|
||||
else
|
||||
@@ -363,7 +363,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
int totalBytesRead = 0;
|
||||
// read the header on the first read
|
||||
byte[] header = new byte[10];
|
||||
int n = _stream.Read(header, 0, header.Length);
|
||||
int n = _stream!.Read(header, 0, header.Length);
|
||||
|
||||
// workitem 8501: handle edge case (decompress empty stream)
|
||||
if (n == 0)
|
||||
@@ -413,7 +413,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
if (_streamMode == StreamMode.Undefined)
|
||||
{
|
||||
if (!this._stream.CanRead) throw new ZlibException("The stream is not readable.");
|
||||
if (!this._stream!.CanRead) throw new ZlibException("The stream is not readable.");
|
||||
// for the first read, set up some controls.
|
||||
_streamMode = StreamMode.Reader;
|
||||
// (The first reference to _z goes through the private accessor which
|
||||
@@ -441,7 +441,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
int rc = 0;
|
||||
|
||||
// set up the output of the deflate/inflate codec:
|
||||
_z.OutputBuffer = buffer;
|
||||
_z!.OutputBuffer = buffer;
|
||||
_z.NextOut = offset;
|
||||
_z.AvailableBytesOut = count;
|
||||
|
||||
@@ -457,7 +457,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
{
|
||||
// No data available, so try to Read data from the captive stream.
|
||||
_z.NextIn = 0;
|
||||
_z.AvailableBytesIn = _stream.Read(_workingBuffer, 0, _workingBuffer.Length);
|
||||
_z.AvailableBytesIn = _stream!.Read(_workingBuffer!, 0, _workingBuffer!.Length);
|
||||
if (_z.AvailableBytesIn == 0)
|
||||
nomoreinput = true;
|
||||
|
||||
@@ -519,22 +519,22 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
public override System.Boolean CanRead
|
||||
{
|
||||
get { return this._stream.CanRead; }
|
||||
get { return this._stream!.CanRead; }
|
||||
}
|
||||
|
||||
public override System.Boolean CanSeek
|
||||
{
|
||||
get { return this._stream.CanSeek; }
|
||||
get { return this._stream!.CanSeek; }
|
||||
}
|
||||
|
||||
public override System.Boolean CanWrite
|
||||
{
|
||||
get { return this._stream.CanWrite; }
|
||||
get { return this._stream!.CanWrite; }
|
||||
}
|
||||
|
||||
public override System.Int64 Length
|
||||
{
|
||||
get { return _stream.Length; }
|
||||
get { return _stream!.Length; }
|
||||
}
|
||||
|
||||
public override long Position
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
/// <summary>
|
||||
/// The buffer from which data is taken.
|
||||
/// </summary>
|
||||
public byte[] InputBuffer;
|
||||
public byte[]? InputBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// An index into the InputBuffer array, indicating where to start reading.
|
||||
@@ -114,7 +114,7 @@ namespace Compress.Support.Compression.Deflate
|
||||
/// <summary>
|
||||
/// Buffer to store output data.
|
||||
/// </summary>
|
||||
public byte[] OutputBuffer;
|
||||
public byte[]? OutputBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// An index into the OutputBuffer array, indicating where to start writing.
|
||||
@@ -138,10 +138,10 @@ namespace Compress.Support.Compression.Deflate
|
||||
/// <summary>
|
||||
/// used for diagnostics, when something goes wrong!
|
||||
/// </summary>
|
||||
public System.String Message;
|
||||
public System.String? Message;
|
||||
|
||||
internal DeflateManager dstate;
|
||||
internal InflateManager istate;
|
||||
internal DeflateManager? dstate;
|
||||
internal InflateManager? istate;
|
||||
|
||||
internal uint _Adler32;
|
||||
|
||||
@@ -659,15 +659,15 @@ namespace Compress.Support.Compression.Deflate
|
||||
// (See also read_buf()).
|
||||
internal void flush_pending()
|
||||
{
|
||||
int len = dstate.pendingCount;
|
||||
int len = dstate!.pendingCount;
|
||||
|
||||
if (len > AvailableBytesOut)
|
||||
len = AvailableBytesOut;
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
if (dstate.pending.Length <= dstate.nextPending ||
|
||||
OutputBuffer.Length <= NextOut ||
|
||||
if (dstate!.pending!.Length <= dstate.nextPending ||
|
||||
OutputBuffer!.Length <= NextOut ||
|
||||
dstate.pending.Length < (dstate.nextPending + len) ||
|
||||
OutputBuffer.Length < (NextOut + len))
|
||||
{
|
||||
@@ -704,11 +704,11 @@ namespace Compress.Support.Compression.Deflate
|
||||
|
||||
AvailableBytesIn -= len;
|
||||
|
||||
if (dstate.WantRfc1950HeaderBytes)
|
||||
if (dstate!.WantRfc1950HeaderBytes)
|
||||
{
|
||||
_Adler32 = Adler.Adler32(_Adler32, InputBuffer, NextIn, len);
|
||||
}
|
||||
Array.Copy(InputBuffer, NextIn, buf, start, len);
|
||||
Array.Copy(InputBuffer!, NextIn, buf, start, len);
|
||||
NextIn += len;
|
||||
TotalBytesIn += len;
|
||||
return len;
|
||||
|
||||
@@ -20,10 +20,10 @@ namespace Compress.Support.Compression.Deflate64
|
||||
{
|
||||
private const int DEFAULT_BUFFER_SIZE = 8192;
|
||||
|
||||
private Stream _stream;
|
||||
private Stream? _stream;
|
||||
private CompressionMode _mode;
|
||||
private InflaterManaged _inflater;
|
||||
private byte[] _buffer;
|
||||
private InflaterManaged? _inflater;
|
||||
private byte[]? _buffer;
|
||||
|
||||
public Deflate64Stream(Stream stream, CompressionMode mode)
|
||||
{
|
||||
@@ -52,7 +52,7 @@ namespace Compress.Support.Compression.Deflate64
|
||||
{
|
||||
Debug.Assert(stream != null);
|
||||
Debug.Assert(method == ZipCompressionMethod.Deflate || method == ZipCompressionMethod.Deflate64);
|
||||
if (!stream.CanRead)
|
||||
if (!stream!.CanRead)
|
||||
{
|
||||
throw new ArgumentException("Deflate64: input stream is not readable", nameof(stream));
|
||||
}
|
||||
@@ -130,7 +130,7 @@ namespace Compress.Support.Compression.Deflate64
|
||||
|
||||
while (true)
|
||||
{
|
||||
bytesRead = _inflater.Inflate(array, currentOffset, remainingCount);
|
||||
bytesRead = _inflater!.Inflate(array, currentOffset, remainingCount);
|
||||
currentOffset += bytesRead;
|
||||
remainingCount -= bytesRead;
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace Compress.Support.Compression.Deflate64
|
||||
break;
|
||||
}
|
||||
|
||||
int bytes = _stream.Read(_buffer, 0, _buffer.Length);
|
||||
int bytes = _stream!.Read(_buffer!, 0, _buffer!.Length);
|
||||
if (bytes <= 0)
|
||||
{
|
||||
break;
|
||||
|
||||
@@ -62,8 +62,8 @@ namespace Compress.Support.Compression.Deflate64
|
||||
|
||||
private readonly OutputWindow _output;
|
||||
private readonly InputBuffer _input;
|
||||
private HuffmanTree _literalLengthTree;
|
||||
private HuffmanTree _distanceTree;
|
||||
private HuffmanTree? _literalLengthTree;
|
||||
private HuffmanTree? _distanceTree;
|
||||
|
||||
private InflaterState _state;
|
||||
//private bool _hasFormatReader;
|
||||
@@ -89,7 +89,7 @@ namespace Compress.Support.Compression.Deflate64
|
||||
private readonly byte[] _codeList; // temporary array to store the code length for literal/Length and distance
|
||||
private readonly byte[] _codeLengthTreeCodeLength;
|
||||
private readonly bool _deflate64;
|
||||
private HuffmanTree _codeLengthTree;
|
||||
private HuffmanTree? _codeLengthTree;
|
||||
|
||||
//private IFileFormatReader _formatReader; // class to decode header and footer (e.g. gzip)
|
||||
|
||||
@@ -397,7 +397,7 @@ namespace Compress.Support.Compression.Deflate64
|
||||
// decode an element from the literal tree
|
||||
|
||||
// TODO: optimize this!!!
|
||||
symbol = _literalLengthTree.GetNextSymbol(_input);
|
||||
symbol = _literalLengthTree!.GetNextSymbol(_input);
|
||||
if (symbol < 0)
|
||||
{
|
||||
// running out of input
|
||||
@@ -469,7 +469,7 @@ namespace Compress.Support.Compression.Deflate64
|
||||
case InflaterState.HaveFullLength:
|
||||
if (_blockType == BlockType.Dynamic)
|
||||
{
|
||||
_distanceCode = _distanceTree.GetNextSymbol(_input);
|
||||
_distanceCode = _distanceTree!.GetNextSymbol(_input);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -613,7 +613,7 @@ namespace Compress.Support.Compression.Deflate64
|
||||
{
|
||||
if (_state == InflaterState.ReadingTreeCodesBefore)
|
||||
{
|
||||
if ((_lengthCode = _codeLengthTree.GetNextSymbol(_input)) < 0)
|
||||
if ((_lengthCode = _codeLengthTree!.GetNextSymbol(_input)) < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Compress.Support.Compression.Deflate64
|
||||
|
||||
internal sealed class InputBuffer
|
||||
{
|
||||
private byte[] _buffer; // byte array to store input
|
||||
private byte[]? _buffer; // byte array to store input
|
||||
private int _start; // start poisition of the buffer
|
||||
private int _end; // end position of the buffer
|
||||
private uint _bitBuffer = 0; // store the bits here, we can quickly shift in this buffer
|
||||
@@ -46,7 +46,7 @@ namespace Compress.Support.Compression.Deflate64
|
||||
return false;
|
||||
}
|
||||
// insert a byte to bitbuffer
|
||||
_bitBuffer |= (uint)_buffer[_start++] << _bitsInBuffer;
|
||||
_bitBuffer |= (uint)_buffer![_start++] << _bitsInBuffer;
|
||||
_bitsInBuffer += 8;
|
||||
|
||||
if (_bitsInBuffer < count)
|
||||
@@ -77,13 +77,13 @@ namespace Compress.Support.Compression.Deflate64
|
||||
{
|
||||
if (_start < _end)
|
||||
{
|
||||
_bitBuffer |= (uint)_buffer[_start++] << _bitsInBuffer;
|
||||
_bitBuffer |= (uint)_buffer![_start++] << _bitsInBuffer;
|
||||
_bitsInBuffer += 8;
|
||||
}
|
||||
|
||||
if (_start < _end)
|
||||
{
|
||||
_bitBuffer |= (uint)_buffer[_start++] << _bitsInBuffer;
|
||||
_bitBuffer |= (uint)_buffer![_start++] << _bitsInBuffer;
|
||||
_bitsInBuffer += 8;
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,7 @@ namespace Compress.Support.Compression.Deflate64
|
||||
{
|
||||
if (_start < _end)
|
||||
{
|
||||
_bitBuffer |= (uint)_buffer[_start++] << _bitsInBuffer;
|
||||
_bitBuffer |= (uint)_buffer![_start++] << _bitsInBuffer;
|
||||
_bitsInBuffer += 8;
|
||||
}
|
||||
}
|
||||
@@ -128,14 +128,14 @@ namespace Compress.Support.Compression.Deflate64
|
||||
Debug.Assert(output != null);
|
||||
Debug.Assert(offset >= 0);
|
||||
Debug.Assert(length >= 0);
|
||||
Debug.Assert(offset <= output.Length - length);
|
||||
Debug.Assert(offset <= output!.Length - length);
|
||||
Debug.Assert((_bitsInBuffer % 8) == 0);
|
||||
|
||||
// Copy the bytes in bitBuffer first.
|
||||
int bytesFromBitBuffer = 0;
|
||||
while (_bitsInBuffer > 0 && length > 0)
|
||||
{
|
||||
output[offset++] = (byte)_bitBuffer;
|
||||
output![offset++] = (byte)_bitBuffer;
|
||||
_bitBuffer >>= 8;
|
||||
_bitsInBuffer -= 8;
|
||||
length--;
|
||||
@@ -153,7 +153,7 @@ namespace Compress.Support.Compression.Deflate64
|
||||
length = avail;
|
||||
}
|
||||
|
||||
Array.Copy(_buffer, _start, output, offset, length);
|
||||
Array.Copy(_buffer!, _start, output, offset, length);
|
||||
_start += length;
|
||||
return bytesFromBitBuffer + length;
|
||||
}
|
||||
@@ -176,7 +176,7 @@ namespace Compress.Support.Compression.Deflate64
|
||||
Debug.Assert(buffer != null);
|
||||
Debug.Assert(offset >= 0);
|
||||
Debug.Assert(length >= 0);
|
||||
Debug.Assert(offset <= buffer.Length - length);
|
||||
Debug.Assert(offset <= buffer!.Length - length);
|
||||
Debug.Assert(_start == _end);
|
||||
|
||||
_buffer = buffer;
|
||||
|
||||
@@ -8,8 +8,8 @@ namespace Compress.Support.Compression.LZ
|
||||
UInt32 _cyclicBufferSize = 0;
|
||||
UInt32 _matchMaxLen;
|
||||
|
||||
UInt32[] _son;
|
||||
UInt32[] _hash;
|
||||
UInt32[]? _son;
|
||||
UInt32[]? _hash;
|
||||
|
||||
UInt32 _cutValue = 0xFF;
|
||||
UInt32 _hashMask;
|
||||
@@ -46,14 +46,14 @@ namespace Compress.Support.Compression.LZ
|
||||
}
|
||||
}
|
||||
|
||||
public new void SetStream(System.IO.Stream stream) { base.SetStream(stream); }
|
||||
public new void SetStream(System.IO.Stream? stream) { base.SetStream(stream); }
|
||||
public new void ReleaseStream() { base.ReleaseStream(); }
|
||||
|
||||
public new void Init()
|
||||
{
|
||||
base.Init();
|
||||
for (UInt32 i = 0; i < _hashSizeSum; i++)
|
||||
_hash[i] = kEmptyHashValue;
|
||||
_hash![i] = kEmptyHashValue;
|
||||
_cyclicBufferPos = 0;
|
||||
ReduceOffsets(-1);
|
||||
}
|
||||
@@ -136,16 +136,16 @@ namespace Compress.Support.Compression.LZ
|
||||
|
||||
if (HASH_ARRAY)
|
||||
{
|
||||
UInt32 temp = Utils.CRC.CRC32Lookup[_bufferBase[cur]] ^ _bufferBase[cur + 1];
|
||||
UInt32 temp = Utils.CRC.CRC32Lookup[_bufferBase![cur]] ^ _bufferBase[cur + 1];
|
||||
hash2Value = temp & (kHash2Size - 1);
|
||||
temp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);
|
||||
hash3Value = temp & (kHash3Size - 1);
|
||||
hashValue = (temp ^ (Utils.CRC.CRC32Lookup[_bufferBase[cur + 3]] << 5)) & _hashMask;
|
||||
}
|
||||
else
|
||||
hashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);
|
||||
hashValue = _bufferBase![cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);
|
||||
|
||||
UInt32 curMatch = _hash[kFixHashSize + hashValue];
|
||||
UInt32 curMatch = _hash![kFixHashSize + hashValue];
|
||||
if (HASH_ARRAY)
|
||||
{
|
||||
UInt32 curMatch2 = _hash[hash2Value];
|
||||
@@ -201,7 +201,7 @@ namespace Compress.Support.Compression.LZ
|
||||
{
|
||||
if (curMatch <= matchMinPos || count-- == 0)
|
||||
{
|
||||
_son[ptr0] = _son[ptr1] = kEmptyHashValue;
|
||||
_son![ptr0] = _son[ptr1] = kEmptyHashValue;
|
||||
break;
|
||||
}
|
||||
UInt32 delta = _pos - curMatch;
|
||||
@@ -222,7 +222,7 @@ namespace Compress.Support.Compression.LZ
|
||||
distances[offset++] = delta - 1;
|
||||
if (len == lenLimit)
|
||||
{
|
||||
_son[ptr1] = _son[cyclicPos];
|
||||
_son![ptr1] = _son[cyclicPos];
|
||||
_son[ptr0] = _son[cyclicPos + 1];
|
||||
break;
|
||||
}
|
||||
@@ -230,14 +230,14 @@ namespace Compress.Support.Compression.LZ
|
||||
}
|
||||
if (_bufferBase[pby1 + len] < _bufferBase[cur + len])
|
||||
{
|
||||
_son[ptr1] = curMatch;
|
||||
_son![ptr1] = curMatch;
|
||||
ptr1 = cyclicPos + 1;
|
||||
curMatch = _son[ptr1];
|
||||
len1 = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
_son[ptr0] = curMatch;
|
||||
_son![ptr0] = curMatch;
|
||||
ptr0 = cyclicPos;
|
||||
curMatch = _son[ptr0];
|
||||
len0 = len;
|
||||
@@ -271,18 +271,18 @@ namespace Compress.Support.Compression.LZ
|
||||
|
||||
if (HASH_ARRAY)
|
||||
{
|
||||
UInt32 temp = Utils.CRC.CRC32Lookup[_bufferBase[cur]] ^ _bufferBase[cur + 1];
|
||||
UInt32 temp = Utils.CRC.CRC32Lookup[_bufferBase![cur]] ^ _bufferBase[cur + 1];
|
||||
UInt32 hash2Value = temp & (kHash2Size - 1);
|
||||
_hash[hash2Value] = _pos;
|
||||
_hash![hash2Value] = _pos;
|
||||
temp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);
|
||||
UInt32 hash3Value = temp & (kHash3Size - 1);
|
||||
_hash[kHash3Offset + hash3Value] = _pos;
|
||||
hashValue = (temp ^ (Utils.CRC.CRC32Lookup[_bufferBase[cur + 3]] << 5)) & _hashMask;
|
||||
}
|
||||
else
|
||||
hashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);
|
||||
hashValue = _bufferBase![cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);
|
||||
|
||||
UInt32 curMatch = _hash[kFixHashSize + hashValue];
|
||||
UInt32 curMatch = _hash![kFixHashSize + hashValue];
|
||||
_hash[kFixHashSize + hashValue] = _pos;
|
||||
|
||||
UInt32 ptr0 = (_cyclicBufferPos << 1) + 1;
|
||||
@@ -296,7 +296,7 @@ namespace Compress.Support.Compression.LZ
|
||||
{
|
||||
if (curMatch <= matchMinPos || count-- == 0)
|
||||
{
|
||||
_son[ptr0] = _son[ptr1] = kEmptyHashValue;
|
||||
_son![ptr0] = _son[ptr1] = kEmptyHashValue;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -314,21 +314,21 @@ namespace Compress.Support.Compression.LZ
|
||||
break;
|
||||
if (len == lenLimit)
|
||||
{
|
||||
_son[ptr1] = _son[cyclicPos];
|
||||
_son![ptr1] = _son[cyclicPos];
|
||||
_son[ptr0] = _son[cyclicPos + 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_bufferBase[pby1 + len] < _bufferBase[cur + len])
|
||||
{
|
||||
_son[ptr1] = curMatch;
|
||||
_son![ptr1] = curMatch;
|
||||
ptr1 = cyclicPos + 1;
|
||||
curMatch = _son[ptr1];
|
||||
len1 = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
_son[ptr0] = curMatch;
|
||||
_son![ptr0] = curMatch;
|
||||
ptr0 = cyclicPos;
|
||||
curMatch = _son[ptr0];
|
||||
len0 = len;
|
||||
@@ -355,8 +355,8 @@ namespace Compress.Support.Compression.LZ
|
||||
void Normalize()
|
||||
{
|
||||
UInt32 subValue = _pos - _cyclicBufferSize;
|
||||
NormalizeLinks(_son, _cyclicBufferSize * 2, subValue);
|
||||
NormalizeLinks(_hash, _hashSizeSum, subValue);
|
||||
NormalizeLinks(_son!, _cyclicBufferSize * 2, subValue);
|
||||
NormalizeLinks(_hash!, _hashSizeSum, subValue);
|
||||
ReduceOffsets((Int32)subValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace Compress.Support.Compression.LZ
|
||||
{
|
||||
internal class InWindow
|
||||
{
|
||||
public Byte[] _bufferBase = null; // pointer to buffer with data
|
||||
System.IO.Stream _stream;
|
||||
public Byte[]? _bufferBase = null; // pointer to buffer with data
|
||||
System.IO.Stream? _stream;
|
||||
UInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done
|
||||
bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Compress.Support.Compression.LZ
|
||||
|
||||
// check negative offset ????
|
||||
for (UInt32 i = 0; i < numBytes; i++)
|
||||
_bufferBase[i] = _bufferBase[offset + i];
|
||||
_bufferBase![i] = _bufferBase[offset + i];
|
||||
_bufferOffset -= offset;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Compress.Support.Compression.LZ
|
||||
int size = (int)((0 - _bufferOffset) + _blockSize - _streamPos);
|
||||
if (size == 0)
|
||||
return;
|
||||
int numReadBytes = _stream != null ? _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size) : 0;
|
||||
int numReadBytes = _stream != null ? _stream.Read(_bufferBase!, (int)(_bufferOffset + _streamPos), size) : 0;
|
||||
if (numReadBytes == 0)
|
||||
{
|
||||
_posLimit = _streamPos;
|
||||
@@ -77,7 +77,7 @@ namespace Compress.Support.Compression.LZ
|
||||
_streamEndWasReached = false;
|
||||
}
|
||||
|
||||
public void SetStream(System.IO.Stream stream)
|
||||
public void SetStream(System.IO.Stream? stream)
|
||||
{
|
||||
_stream = stream;
|
||||
if (_streamEndWasReached)
|
||||
@@ -110,7 +110,7 @@ namespace Compress.Support.Compression.LZ
|
||||
}
|
||||
}
|
||||
|
||||
public Byte GetIndexByte(Int32 index) { return _bufferBase[_bufferOffset + _pos + index]; }
|
||||
public Byte GetIndexByte(Int32 index) { return _bufferBase![_bufferOffset + _pos + index]; }
|
||||
|
||||
// index + limit have not to exceed _keepSizeAfter;
|
||||
public UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)
|
||||
@@ -123,7 +123,7 @@ namespace Compress.Support.Compression.LZ
|
||||
UInt32 pby = _bufferOffset + _pos + (UInt32)index;
|
||||
|
||||
UInt32 i;
|
||||
for (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++) ;
|
||||
for (i = 0; i < limit && _bufferBase![pby + i] == _bufferBase[pby + i - distance]; i++) ;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@ namespace Compress.Support.Compression.LZ
|
||||
{
|
||||
internal class OutWindow
|
||||
{
|
||||
byte[] _buffer = null;
|
||||
byte[]? _buffer = null;
|
||||
int _windowSize = 0;
|
||||
int _pos;
|
||||
int _streamPos;
|
||||
int _pendingLen;
|
||||
int _pendingDist;
|
||||
System.IO.Stream _stream;
|
||||
System.IO.Stream? _stream;
|
||||
|
||||
public long Total;
|
||||
public long Limit;
|
||||
@@ -20,7 +20,7 @@ namespace Compress.Support.Compression.LZ
|
||||
if (_windowSize != windowSize)
|
||||
_buffer = new byte[windowSize];
|
||||
else
|
||||
_buffer[windowSize - 1] = 0;
|
||||
_buffer![windowSize - 1] = 0;
|
||||
_windowSize = windowSize;
|
||||
_pos = 0;
|
||||
_streamPos = 0;
|
||||
@@ -67,7 +67,7 @@ namespace Compress.Support.Compression.LZ
|
||||
int size = _pos - _streamPos;
|
||||
if (size == 0)
|
||||
return;
|
||||
_stream.Write(_buffer, _streamPos, size);
|
||||
_stream.Write(_buffer!, _streamPos, size);
|
||||
if (_pos >= _windowSize)
|
||||
_pos = 0;
|
||||
_streamPos = _pos;
|
||||
@@ -83,7 +83,7 @@ namespace Compress.Support.Compression.LZ
|
||||
{
|
||||
if (pos >= _windowSize)
|
||||
pos = 0;
|
||||
_buffer[_pos++] = _buffer[pos++];
|
||||
_buffer![_pos++] = _buffer[pos++];
|
||||
Total++;
|
||||
if (_pos >= _windowSize)
|
||||
Flush();
|
||||
@@ -94,7 +94,7 @@ namespace Compress.Support.Compression.LZ
|
||||
|
||||
public void PutByte(byte b)
|
||||
{
|
||||
_buffer[_pos++] = b;
|
||||
_buffer![_pos++] = b;
|
||||
Total++;
|
||||
if (_pos >= _windowSize)
|
||||
Flush();
|
||||
@@ -105,7 +105,7 @@ namespace Compress.Support.Compression.LZ
|
||||
int pos = _pos - distance - 1;
|
||||
if (pos < 0)
|
||||
pos += _windowSize;
|
||||
return _buffer[pos];
|
||||
return _buffer![pos];
|
||||
}
|
||||
|
||||
public int CopyStream(System.IO.Stream stream, int len)
|
||||
@@ -118,7 +118,7 @@ namespace Compress.Support.Compression.LZ
|
||||
curSize = (int)(Limit - Total);
|
||||
if (curSize > size)
|
||||
curSize = size;
|
||||
int numReadBytes = stream.Read(_buffer, _pos, curSize);
|
||||
int numReadBytes = stream.Read(_buffer!, _pos, curSize);
|
||||
if (numReadBytes == 0)
|
||||
throw new DataErrorException();
|
||||
size -= numReadBytes;
|
||||
@@ -159,7 +159,7 @@ namespace Compress.Support.Compression.LZ
|
||||
int size = _pos - _streamPos;
|
||||
if (size > count)
|
||||
size = count;
|
||||
System.Buffer.BlockCopy(_buffer, _streamPos, buffer, offset, size);
|
||||
System.Buffer.BlockCopy(_buffer!, _streamPos, buffer, offset, size);
|
||||
_streamPos += size;
|
||||
if (_streamPos >= _windowSize)
|
||||
{
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
}
|
||||
}
|
||||
|
||||
Decoder2[] m_Coders;
|
||||
Decoder2[]? m_Coders;
|
||||
int m_NumPrevBits;
|
||||
int m_NumPosBits;
|
||||
uint m_PosMask;
|
||||
@@ -116,20 +116,20 @@ namespace Compress.Support.Compression.LZMA
|
||||
{
|
||||
uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);
|
||||
for (uint i = 0; i < numStates; i++)
|
||||
m_Coders[i].Init();
|
||||
m_Coders![i].Init();
|
||||
}
|
||||
|
||||
uint GetState(uint pos, byte prevByte)
|
||||
{ return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); }
|
||||
|
||||
public byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)
|
||||
{ return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }
|
||||
{ return m_Coders![GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }
|
||||
|
||||
public byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)
|
||||
{ return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }
|
||||
{ return m_Coders![GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }
|
||||
};
|
||||
|
||||
LZ.OutWindow m_OutWindow;
|
||||
LZ.OutWindow? m_OutWindow;
|
||||
|
||||
BitDecoder[] m_IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];
|
||||
BitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates];
|
||||
@@ -230,7 +230,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
{
|
||||
if (m_OutWindow == null)
|
||||
CreateDictionary();
|
||||
m_OutWindow.Init(outStream);
|
||||
m_OutWindow!.Init(outStream);
|
||||
if (outSize > 0)
|
||||
m_OutWindow.SetLimit(outSize);
|
||||
else
|
||||
@@ -372,7 +372,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
{
|
||||
if (m_OutWindow == null)
|
||||
CreateDictionary();
|
||||
m_OutWindow.Train(stream);
|
||||
m_OutWindow!.Train(stream);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
}
|
||||
}
|
||||
|
||||
Encoder2[] m_Coders;
|
||||
Encoder2[]? m_Coders;
|
||||
int m_NumPrevBits;
|
||||
int m_NumPosBits;
|
||||
uint m_PosMask;
|
||||
@@ -155,11 +155,11 @@ namespace Compress.Support.Compression.LZMA
|
||||
{
|
||||
uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);
|
||||
for (uint i = 0; i < numStates; i++)
|
||||
m_Coders[i].Init();
|
||||
m_Coders![i].Init();
|
||||
}
|
||||
|
||||
public Encoder2 GetSubCoder(UInt32 pos, Byte prevByte)
|
||||
{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits))]; }
|
||||
{ return m_Coders![((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits))]; }
|
||||
}
|
||||
|
||||
class LenEncoder
|
||||
@@ -299,7 +299,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
public bool IsShortRep() { return (BackPrev == 0); }
|
||||
};
|
||||
Optimal[] _optimum = new Optimal[kNumOpts];
|
||||
LZ.BinTree _matchFinder = null;
|
||||
LZ.BinTree? _matchFinder = null;
|
||||
RangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder();
|
||||
|
||||
RangeCoder.BitEncoder[] _isMatch = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];
|
||||
@@ -350,7 +350,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
|
||||
Int64 nowPos64;
|
||||
bool _finished;
|
||||
System.IO.Stream _inStream;
|
||||
System.IO.Stream? _inStream;
|
||||
|
||||
EMatchFinderType _matchFinderType = EMatchFinderType.BT4;
|
||||
bool _writeEndMark = false;
|
||||
@@ -430,7 +430,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
void ReadMatchDistances(out UInt32 lenRes, out UInt32 numDistancePairs)
|
||||
{
|
||||
lenRes = 0;
|
||||
numDistancePairs = _matchFinder.GetMatches(_matchDistances);
|
||||
numDistancePairs = _matchFinder!.GetMatches(_matchDistances);
|
||||
if (numDistancePairs > 0)
|
||||
{
|
||||
lenRes = _matchDistances[numDistancePairs - 2];
|
||||
@@ -446,7 +446,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
{
|
||||
if (num > 0)
|
||||
{
|
||||
_matchFinder.Skip(num);
|
||||
_matchFinder!.Skip(num);
|
||||
_additionalOffset += num;
|
||||
}
|
||||
}
|
||||
@@ -558,7 +558,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
_longestMatchWasFound = false;
|
||||
}
|
||||
|
||||
UInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;
|
||||
UInt32 numAvailableBytes = _matchFinder!.GetNumAvailableBytes() + 1;
|
||||
if (numAvailableBytes < 2)
|
||||
{
|
||||
backRes = 0xFFFFFFFF;
|
||||
@@ -1067,7 +1067,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
|
||||
if (_inStream != null)
|
||||
{
|
||||
_matchFinder.SetStream(_inStream);
|
||||
_matchFinder!.SetStream(_inStream);
|
||||
_needReleaseMFStream = true;
|
||||
_inStream = null;
|
||||
}
|
||||
@@ -1082,17 +1082,17 @@ namespace Compress.Support.Compression.LZMA
|
||||
{
|
||||
if (_trainSize > 0)
|
||||
{
|
||||
for (; _trainSize > 0 && (!_processingMode || !_matchFinder.IsDataStarved); _trainSize--)
|
||||
_matchFinder.Skip(1);
|
||||
for (; _trainSize > 0 && (!_processingMode || !_matchFinder!.IsDataStarved); _trainSize--)
|
||||
_matchFinder!.Skip(1);
|
||||
if (_trainSize == 0)
|
||||
_previousByte = _matchFinder.GetIndexByte(-1);
|
||||
_previousByte = _matchFinder!.GetIndexByte(-1);
|
||||
}
|
||||
if (_processingMode && _matchFinder.IsDataStarved)
|
||||
if (_processingMode && _matchFinder!.IsDataStarved)
|
||||
{
|
||||
_finished = false;
|
||||
return;
|
||||
}
|
||||
if (_matchFinder.GetNumAvailableBytes() == 0)
|
||||
if (_matchFinder!.GetNumAvailableBytes() == 0)
|
||||
{
|
||||
Flush((UInt32)nowPos64);
|
||||
return;
|
||||
@@ -1108,12 +1108,12 @@ namespace Compress.Support.Compression.LZMA
|
||||
_additionalOffset--;
|
||||
nowPos64++;
|
||||
}
|
||||
if (_processingMode && _matchFinder.IsDataStarved)
|
||||
if (_processingMode && _matchFinder!.IsDataStarved)
|
||||
{
|
||||
_finished = false;
|
||||
return;
|
||||
}
|
||||
if (_matchFinder.GetNumAvailableBytes() == 0)
|
||||
if (_matchFinder!.GetNumAvailableBytes() == 0)
|
||||
{
|
||||
Flush((UInt32)nowPos64);
|
||||
return;
|
||||
@@ -1270,7 +1270,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
ReleaseOutStream();
|
||||
}
|
||||
|
||||
public void SetStreams(System.IO.Stream inStream, System.IO.Stream outStream,
|
||||
public void SetStreams(System.IO.Stream? inStream, System.IO.Stream outStream,
|
||||
Int64 inSize, Int64 outSize)
|
||||
{
|
||||
_inStream = inStream;
|
||||
@@ -1278,7 +1278,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
Create();
|
||||
SetOutStream(outStream);
|
||||
Init();
|
||||
_matchFinder.Init();
|
||||
_matchFinder!.Init();
|
||||
|
||||
// if (!_fastMode)
|
||||
{
|
||||
@@ -1323,9 +1323,9 @@ namespace Compress.Support.Compression.LZMA
|
||||
}
|
||||
}
|
||||
|
||||
public long Code(System.IO.Stream inStream, bool final)
|
||||
public long Code(System.IO.Stream? inStream, bool final)
|
||||
{
|
||||
_matchFinder.SetStream(inStream);
|
||||
_matchFinder!.SetStream(inStream);
|
||||
_processingMode = !final;
|
||||
try
|
||||
{
|
||||
@@ -1354,7 +1354,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
_trainSize = (uint)trainStream.Length;
|
||||
if (_trainSize > 0)
|
||||
{
|
||||
_matchFinder.SetStream(trainStream);
|
||||
_matchFinder!.SetStream(trainStream);
|
||||
for (; _trainSize > 0 && !_matchFinder.IsDataStarved; _trainSize--)
|
||||
_matchFinder.Skip(1);
|
||||
if (_trainSize == 0)
|
||||
|
||||
@@ -6,14 +6,14 @@ namespace Compress.Support.Compression.LZMA
|
||||
{
|
||||
public class LzmaStream : Stream
|
||||
{
|
||||
private Stream inputStream;
|
||||
private Stream? inputStream;
|
||||
private long inputSize;
|
||||
private long outputSize;
|
||||
|
||||
private int dictionarySize;
|
||||
private OutWindow outWindow = new OutWindow();
|
||||
private RangeCoder.Decoder rangeDecoder = new RangeCoder.Decoder();
|
||||
private Decoder decoder;
|
||||
private Decoder? decoder;
|
||||
|
||||
private long position = 0;
|
||||
private bool endReached = false;
|
||||
@@ -28,7 +28,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
private bool needProps = true;
|
||||
private byte[] props = new byte[5];
|
||||
|
||||
private Encoder encoder;
|
||||
private Encoder? encoder;
|
||||
|
||||
public LzmaStream(byte[] properties, Stream inputStream)
|
||||
: this(properties, inputStream, -1, -1, null, properties.Length < 5)
|
||||
@@ -46,7 +46,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
}
|
||||
|
||||
public LzmaStream(byte[] properties, Stream inputStream, long inputSize, long outputSize,
|
||||
Stream presetDictionary, bool isLZMA2)
|
||||
Stream? presetDictionary, bool isLZMA2)
|
||||
{
|
||||
this.inputStream = inputStream;
|
||||
this.inputSize = inputSize;
|
||||
@@ -91,7 +91,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
{
|
||||
}
|
||||
|
||||
public LzmaStream(LzmaEncoderProperties properties, bool isLZMA2, Stream presetDictionary, Stream outputStream)
|
||||
public LzmaStream(LzmaEncoderProperties properties, bool isLZMA2, Stream? presetDictionary, Stream outputStream)
|
||||
{
|
||||
this.isLZMA2 = isLZMA2;
|
||||
availableBytes = 0;
|
||||
@@ -182,9 +182,9 @@ namespace Compress.Support.Compression.LZMA
|
||||
outWindow.SetLimit(toProcess);
|
||||
if(uncompressedChunk)
|
||||
{
|
||||
inputPosition += outWindow.CopyStream(inputStream, toProcess);
|
||||
inputPosition += outWindow.CopyStream(inputStream!, toProcess);
|
||||
}
|
||||
else if(decoder.Code(dictionarySize, outWindow, rangeDecoder)
|
||||
else if(decoder!.Code(dictionarySize, outWindow, rangeDecoder)
|
||||
&& outputSize < 0)
|
||||
{
|
||||
availableBytes = outWindow.AvailableBytes;
|
||||
@@ -220,7 +220,7 @@ namespace Compress.Support.Compression.LZMA
|
||||
|
||||
private void decodeChunkHeader()
|
||||
{
|
||||
int control = inputStream.ReadByte();
|
||||
int control = inputStream!.ReadByte();
|
||||
inputPosition++;
|
||||
|
||||
if (control == 0x00)
|
||||
|
||||
@@ -30,14 +30,14 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
internal struct MemoryNode
|
||||
{
|
||||
public uint Address;
|
||||
public byte[] Memory;
|
||||
public byte[]? Memory;
|
||||
public static readonly MemoryNode Zero = new MemoryNode(0, null);
|
||||
public const int Size = 12;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MemoryNode"/> structure.
|
||||
/// </summary>
|
||||
public MemoryNode(uint address, byte[] memory)
|
||||
public MemoryNode(uint address, byte[]? memory)
|
||||
{
|
||||
Address = address;
|
||||
Memory = memory;
|
||||
@@ -48,10 +48,10 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
public uint Stamp
|
||||
{
|
||||
get { return ((uint) Memory[Address]) | ((uint) Memory[Address + 1]) << 8 | ((uint) Memory[Address + 2]) << 16 | ((uint) Memory[Address + 3]) << 24; }
|
||||
get { return ((uint) Memory![Address]) | ((uint) Memory[Address + 1]) << 8 | ((uint) Memory[Address + 2]) << 16 | ((uint) Memory[Address + 3]) << 24; }
|
||||
set
|
||||
{
|
||||
Memory[Address] = (byte) value;
|
||||
Memory![Address] = (byte) value;
|
||||
Memory[Address + 1] = (byte) (value >> 8);
|
||||
Memory[Address + 2] = (byte) (value >> 16);
|
||||
Memory[Address + 3] = (byte) (value >> 24);
|
||||
@@ -63,10 +63,10 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
public MemoryNode Next
|
||||
{
|
||||
get { return new MemoryNode(((uint) Memory[Address + 4]) | ((uint) Memory[Address + 5]) << 8 | ((uint) Memory[Address + 6]) << 16 | ((uint) Memory[Address + 7]) << 24, Memory); }
|
||||
get { return new MemoryNode(((uint) Memory![Address + 4]) | ((uint) Memory[Address + 5]) << 8 | ((uint) Memory[Address + 6]) << 16 | ((uint) Memory[Address + 7]) << 24, Memory); }
|
||||
set
|
||||
{
|
||||
Memory[Address + 4] = (byte) value.Address;
|
||||
Memory![Address + 4] = (byte) value.Address;
|
||||
Memory[Address + 5] = (byte) (value.Address >> 8);
|
||||
Memory[Address + 6] = (byte) (value.Address >> 16);
|
||||
Memory[Address + 7] = (byte) (value.Address >> 24);
|
||||
@@ -78,10 +78,10 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
public uint UnitCount
|
||||
{
|
||||
get { return ((uint) Memory[Address + 8]) | ((uint) Memory[Address + 9]) << 8 | ((uint) Memory[Address + 10]) << 16 | ((uint) Memory[Address + 11]) << 24; }
|
||||
get { return ((uint) Memory![Address + 8]) | ((uint) Memory[Address + 9]) << 8 | ((uint) Memory[Address + 10]) << 16 | ((uint) Memory[Address + 11]) << 24; }
|
||||
set
|
||||
{
|
||||
Memory[Address + 8] = (byte) value;
|
||||
Memory![Address + 8] = (byte) value;
|
||||
Memory[Address + 9] = (byte) (value >> 8);
|
||||
Memory[Address + 10] = (byte) (value >> 16);
|
||||
Memory[Address + 11] = (byte) (value >> 24);
|
||||
@@ -224,7 +224,7 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
/// <returns>true if obj and this instance are the same type and represent the same value; otherwise, false.</returns>
|
||||
/// <param name="obj">Another object to compare to.</param>
|
||||
public override bool Equals(object obj)
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is MemoryNode)
|
||||
{
|
||||
|
||||
@@ -23,14 +23,14 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
internal struct Pointer
|
||||
{
|
||||
public uint Address;
|
||||
public byte[] Memory;
|
||||
public byte[]? Memory;
|
||||
public static readonly Pointer Zero = new Pointer(0, null);
|
||||
public const int Size = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Pointer"/> structure.
|
||||
/// </summary>
|
||||
public Pointer(uint address, byte[] memory)
|
||||
public Pointer(uint address, byte[]? memory)
|
||||
{
|
||||
Address = address;
|
||||
Memory = memory;
|
||||
@@ -49,7 +49,7 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
if (Address == 0)
|
||||
throw new InvalidOperationException("The pointer being indexed is a null pointer.");
|
||||
#endif
|
||||
return Memory[Address + offset];
|
||||
return Memory![Address + offset];
|
||||
}
|
||||
set
|
||||
{
|
||||
@@ -57,7 +57,7 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
if (Address == 0)
|
||||
throw new InvalidOperationException("The pointer being indexed is a null pointer.");
|
||||
#endif
|
||||
Memory[Address + offset] = value;
|
||||
Memory![Address + offset] = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
/// <returns>true if obj and this instance are the same type and represent the same value; otherwise, false.</returns>
|
||||
/// <param name="obj">Another object to compare to.</param>
|
||||
public override bool Equals(object obj)
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is Pointer)
|
||||
{
|
||||
|
||||
@@ -24,14 +24,14 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
internal struct PpmContext
|
||||
{
|
||||
public uint Address;
|
||||
public byte[] Memory;
|
||||
public byte[]? Memory;
|
||||
public static readonly PpmContext Zero = new PpmContext(0, null);
|
||||
public const int Size = 12;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PpmContext"/> structure.
|
||||
/// </summary>
|
||||
public PpmContext(uint address, byte[] memory)
|
||||
public PpmContext(uint address, byte[]? memory)
|
||||
{
|
||||
Address = address;
|
||||
Memory = memory;
|
||||
@@ -42,8 +42,8 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
public byte NumberStatistics
|
||||
{
|
||||
get { return Memory[Address]; }
|
||||
set { Memory[Address] = value; }
|
||||
get { return Memory![Address]; }
|
||||
set { Memory![Address] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -51,8 +51,8 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
public byte Flags
|
||||
{
|
||||
get { return Memory[Address + 1]; }
|
||||
set { Memory[Address + 1] = value; }
|
||||
get { return Memory![Address + 1]; }
|
||||
set { Memory![Address + 1] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -60,10 +60,10 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
public ushort SummaryFrequency
|
||||
{
|
||||
get { return (ushort)(((ushort)Memory[Address + 2]) | ((ushort)Memory[Address + 3]) << 8); }
|
||||
get { return (ushort)(((ushort)Memory![Address + 2]) | ((ushort)Memory[Address + 3]) << 8); }
|
||||
set
|
||||
{
|
||||
Memory[Address + 2] = (byte)value;
|
||||
Memory![Address + 2] = (byte)value;
|
||||
Memory[Address + 3] = (byte)(value >> 8);
|
||||
}
|
||||
}
|
||||
@@ -73,10 +73,10 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
public PpmState Statistics
|
||||
{
|
||||
get { return new PpmState(((uint)Memory[Address + 4]) | ((uint)Memory[Address + 5]) << 8 | ((uint)Memory[Address + 6]) << 16 | ((uint)Memory[Address + 7]) << 24, Memory); }
|
||||
get { return new PpmState(((uint)Memory![Address + 4]) | ((uint)Memory[Address + 5]) << 8 | ((uint)Memory[Address + 6]) << 16 | ((uint)Memory[Address + 7]) << 24, Memory); }
|
||||
set
|
||||
{
|
||||
Memory[Address + 4] = (byte)value.Address;
|
||||
Memory![Address + 4] = (byte)value.Address;
|
||||
Memory[Address + 5] = (byte)(value.Address >> 8);
|
||||
Memory[Address + 6] = (byte)(value.Address >> 16);
|
||||
Memory[Address + 7] = (byte)(value.Address >> 24);
|
||||
@@ -88,10 +88,10 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
public PpmContext Suffix
|
||||
{
|
||||
get { return new PpmContext(((uint)Memory[Address + 8]) | ((uint)Memory[Address + 9]) << 8 | ((uint)Memory[Address + 10]) << 16 | ((uint)Memory[Address + 11]) << 24, Memory); }
|
||||
get { return new PpmContext(((uint)Memory![Address + 8]) | ((uint)Memory[Address + 9]) << 8 | ((uint)Memory[Address + 10]) << 16 | ((uint)Memory[Address + 11]) << 24, Memory); }
|
||||
set
|
||||
{
|
||||
Memory[Address + 8] = (byte)value.Address;
|
||||
Memory![Address + 8] = (byte)value.Address;
|
||||
Memory[Address + 9] = (byte)(value.Address >> 8);
|
||||
Memory[Address + 10] = (byte)(value.Address >> 16);
|
||||
Memory[Address + 11] = (byte)(value.Address >> 24);
|
||||
@@ -136,8 +136,8 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "The property getter is provided for completeness.")]
|
||||
public byte FirstStateSymbol
|
||||
{
|
||||
get { return Memory[Address + 2]; }
|
||||
set { Memory[Address + 2] = value; }
|
||||
get { return Memory![Address + 2]; }
|
||||
set { Memory![Address + 2] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -147,8 +147,8 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
public byte FirstStateFrequency
|
||||
{
|
||||
get { return Memory[Address + 3]; }
|
||||
set { Memory[Address + 3] = value; }
|
||||
get { return Memory![Address + 3]; }
|
||||
set { Memory![Address + 3] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -158,10 +158,10 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "The property getter is provided for completeness.")]
|
||||
public PpmContext FirstStateSuccessor
|
||||
{
|
||||
get { return new PpmContext(((uint)Memory[Address + 4]) | ((uint)Memory[Address + 5]) << 8 | ((uint)Memory[Address + 6]) << 16 | ((uint)Memory[Address + 7]) << 24, Memory); }
|
||||
get { return new PpmContext(((uint)Memory![Address + 4]) | ((uint)Memory[Address + 5]) << 8 | ((uint)Memory[Address + 6]) << 16 | ((uint)Memory[Address + 7]) << 24, Memory); }
|
||||
set
|
||||
{
|
||||
Memory[Address + 4] = (byte)value.Address;
|
||||
Memory![Address + 4] = (byte)value.Address;
|
||||
Memory[Address + 5] = (byte)(value.Address >> 8);
|
||||
Memory[Address + 6] = (byte)(value.Address >> 16);
|
||||
Memory[Address + 7] = (byte)(value.Address >> 24);
|
||||
@@ -251,7 +251,7 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
/// <returns>true if obj and this instance are the same type and represent the same value; otherwise, false.</returns>
|
||||
/// <param name="obj">Another object to compare to.</param>
|
||||
public override bool Equals(object obj)
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is PpmContext)
|
||||
{
|
||||
|
||||
@@ -22,14 +22,14 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
internal struct PpmState
|
||||
{
|
||||
public uint Address;
|
||||
public byte[] Memory;
|
||||
public byte[]? Memory;
|
||||
public static readonly PpmState Zero = new PpmState(0, null);
|
||||
public const int Size = 6;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PpmState"/> structure.
|
||||
/// </summary>
|
||||
public PpmState(uint address, byte[] memory)
|
||||
public PpmState(uint address, byte[]? memory)
|
||||
{
|
||||
Address = address;
|
||||
Memory = memory;
|
||||
@@ -40,8 +40,8 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
public byte Symbol
|
||||
{
|
||||
get { return Memory[Address]; }
|
||||
set { Memory[Address] = value; }
|
||||
get { return Memory![Address]; }
|
||||
set { Memory![Address] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,8 +49,8 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
public byte Frequency
|
||||
{
|
||||
get { return Memory[Address + 1]; }
|
||||
set { Memory[Address + 1] = value; }
|
||||
get { return Memory![Address + 1]; }
|
||||
set { Memory![Address + 1] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -58,10 +58,10 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
public Model.PpmContext Successor
|
||||
{
|
||||
get { return new Model.PpmContext(((uint) Memory[Address + 2]) | ((uint) Memory[Address + 3]) << 8 | ((uint) Memory[Address + 4]) << 16 | ((uint) Memory[Address + 5]) << 24, Memory); }
|
||||
get { return new Model.PpmContext(((uint) Memory![Address + 2]) | ((uint) Memory[Address + 3]) << 8 | ((uint) Memory[Address + 4]) << 16 | ((uint) Memory[Address + 5]) << 24, Memory); }
|
||||
set
|
||||
{
|
||||
Memory[Address + 2] = (byte) value.Address;
|
||||
Memory![Address + 2] = (byte) value.Address;
|
||||
Memory[Address + 3] = (byte) (value.Address >> 8);
|
||||
Memory[Address + 4] = (byte) (value.Address >> 16);
|
||||
Memory[Address + 5] = (byte) (value.Address >> 24);
|
||||
@@ -184,7 +184,7 @@ namespace Compress.Support.Compression.PPmd.I1
|
||||
/// </summary>
|
||||
/// <returns>true if obj and this instance are the same type and represent the same value; otherwise, false.</returns>
|
||||
/// <param name="obj">Another object to compare to.</param>
|
||||
public override bool Equals(object obj)
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is PpmState)
|
||||
{
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace Compress.ZipFile
|
||||
return zRet;
|
||||
}
|
||||
|
||||
ulong endOfCentralDir = (ulong)_zipFs.Position;
|
||||
ulong endOfCentralDir = (ulong)_zipFs!.Position;
|
||||
zRet = EndOfCentralDirRead();
|
||||
if (zRet != ZipReturn.ZipGood)
|
||||
{
|
||||
@@ -198,7 +198,7 @@ namespace Compress.ZipFile
|
||||
{
|
||||
for (int i = 0; i < _localFilesCount - 1; i++)
|
||||
{
|
||||
if (CompressUtils.TrrntZipStringCompare(_localFiles[i].Filename, _localFiles[i + 1].Filename) < 0)
|
||||
if (CompressUtils.TrrntZipStringCompare(_localFiles[i].Filename!, _localFiles[i + 1].Filename!) < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -213,14 +213,14 @@ namespace Compress.ZipFile
|
||||
for (int i = 0; i < _localFilesCount - 1; i++)
|
||||
{
|
||||
// see if we found a directory
|
||||
string filename0 = _localFiles[i].Filename;
|
||||
string filename0 = _localFiles[i].Filename!;
|
||||
if (filename0.Substring(filename0.Length - 1, 1) != "/")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// see if the next file is in that directory
|
||||
string filename1 = _localFiles[i + 1].Filename;
|
||||
string filename1 = _localFiles[i + 1].Filename!;
|
||||
if (filename1.Length <= filename0.Length)
|
||||
{
|
||||
continue;
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Compress.ZipFile
|
||||
if (localFilesCount > 0)
|
||||
{
|
||||
// check that filenames are in trrntzip order
|
||||
string lastFilename = _localFiles[localFilesCount - 1].Filename;
|
||||
string lastFilename = _localFiles[localFilesCount - 1].Filename!;
|
||||
if (CompressUtils.TrrntZipStringCompare(lastFilename, filename) > 0)
|
||||
validTrrntzip = ZipReturn.ZipTrrntzipIncorrectFileOrder;
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@ namespace Compress.gZip
|
||||
{
|
||||
public class gZip : ICompress
|
||||
{
|
||||
private FileInfo _zipFileInfo;
|
||||
private Stream _zipFs;
|
||||
private Stream _compressionStream;
|
||||
private FileInfo? _zipFileInfo;
|
||||
private Stream? _zipFs;
|
||||
private Stream? _compressionStream;
|
||||
|
||||
private byte[] CRC;
|
||||
private byte[]? CRC;
|
||||
private ulong UnCompressedSize;
|
||||
public ulong CompressedSize { get; private set; }
|
||||
private uint MTime;
|
||||
@@ -35,7 +35,7 @@ namespace Compress.gZip
|
||||
{
|
||||
Filename = Path.GetFileName(ZipFilename),
|
||||
UncompressedSize = UnCompressedSize,
|
||||
CRC = this.CRC,
|
||||
CRC = this.CRC!,
|
||||
IsDirectory = false,
|
||||
ModifiedTime = MTime == 0 ? null : (long?)CompressUtils.UtcTicksFromUnixDateTime((int)MTime)
|
||||
};
|
||||
@@ -98,7 +98,7 @@ namespace Compress.gZip
|
||||
|
||||
}
|
||||
|
||||
public ZipReturn ZipFileOpen(Stream inStream)
|
||||
public ZipReturn ZipFileOpen(Stream? inStream)
|
||||
{
|
||||
ZipFileClose();
|
||||
ZipStatus = ZipStatus.None;
|
||||
@@ -112,9 +112,9 @@ namespace Compress.gZip
|
||||
private ZipReturn ZipFileReadHeaders()
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using BinaryReader zipBr = new(_zipFs, Encoding.UTF8);
|
||||
using BinaryReader zipBr = new(_zipFs!, Encoding.UTF8);
|
||||
#else
|
||||
using BinaryReader zipBr = new(_zipFs, Encoding.UTF8, true);
|
||||
using BinaryReader zipBr = new(_zipFs!, Encoding.UTF8, true);
|
||||
#endif
|
||||
|
||||
byte ID1 = zipBr.ReadByte();
|
||||
@@ -122,14 +122,14 @@ namespace Compress.gZip
|
||||
|
||||
if ((ID1 != 0x1f) || (ID2 != 0x8b))
|
||||
{
|
||||
_zipFs.Close();
|
||||
_zipFs!.Close();
|
||||
return ZipReturn.ZipSignatureError;
|
||||
}
|
||||
|
||||
byte CM = zipBr.ReadByte();
|
||||
if (CM != 8)
|
||||
{
|
||||
_zipFs.Close();
|
||||
_zipFs!.Close();
|
||||
return ZipReturn.ZipUnsupportedCompression;
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ namespace Compress.gZip
|
||||
uint crc16 = zipBr.ReadUInt16();
|
||||
}
|
||||
|
||||
CompressedSize = (ulong)(_zipFs.Length - _zipFs.Position) - 8;
|
||||
CompressedSize = (ulong)(_zipFs!.Length - _zipFs.Position) - 8;
|
||||
|
||||
dataStartPos = _zipFs.Position;
|
||||
|
||||
@@ -283,12 +283,12 @@ namespace Compress.gZip
|
||||
}
|
||||
}
|
||||
|
||||
public ZipReturn ZipFileOpenReadStream(int index, out Stream stream, out ulong streamSize)
|
||||
public ZipReturn ZipFileOpenReadStream(int index, out Stream? stream, out ulong streamSize)
|
||||
{
|
||||
return ZipFileOpenReadStream(index, false, out stream, out streamSize);
|
||||
}
|
||||
|
||||
public ZipReturn ZipFileOpenReadStream(int index, bool raw, out Stream stream, out ulong streamSize)
|
||||
public ZipReturn ZipFileOpenReadStream(int index, bool raw, out Stream? stream, out ulong streamSize)
|
||||
{
|
||||
ZipFileCloseReadStream();
|
||||
stream = null;
|
||||
@@ -299,7 +299,7 @@ namespace Compress.gZip
|
||||
return ZipReturn.ZipReadingFromOutputFile;
|
||||
}
|
||||
|
||||
_zipFs.Position = dataStartPos;
|
||||
_zipFs!.Position = dataStartPos;
|
||||
if (raw)
|
||||
{
|
||||
stream = _zipFs;
|
||||
@@ -316,14 +316,14 @@ namespace Compress.gZip
|
||||
return ZipReturn.ZipGood;
|
||||
}
|
||||
|
||||
public byte[] ExtraData;
|
||||
public byte[]? ExtraData;
|
||||
|
||||
public ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong unCompressedSize, ushort compressionMethod, out Stream stream, TimeStamps dateTime)
|
||||
public ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong unCompressedSize, ushort compressionMethod, out Stream? stream, TimeStamps? dateTime)
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryWriter zipBw = new(_zipFs, Encoding.UTF8))
|
||||
using (BinaryWriter zipBw = new(_zipFs!, Encoding.UTF8))
|
||||
#else
|
||||
using (BinaryWriter zipBw = new(_zipFs, Encoding.UTF8, true))
|
||||
using (BinaryWriter zipBw = new(_zipFs!, Encoding.UTF8, true))
|
||||
#endif
|
||||
{
|
||||
UnCompressedSize = unCompressedSize;
|
||||
@@ -355,7 +355,7 @@ namespace Compress.gZip
|
||||
|
||||
_compressionStream = raw
|
||||
? _zipFs
|
||||
: new ZlibBaseStream(_zipFs, CompressionMode.Compress, CompressionLevel.BestCompression, ZlibStreamFlavor.DEFLATE, true);
|
||||
: new ZlibBaseStream(_zipFs!, CompressionMode.Compress, CompressionLevel.BestCompression, ZlibStreamFlavor.DEFLATE, true);
|
||||
|
||||
zipBw.Flush();
|
||||
zipBw.Close();
|
||||
@@ -428,7 +428,7 @@ namespace Compress.gZip
|
||||
|
||||
_compressionStream = null;
|
||||
|
||||
CompressedSize = (ulong)(_zipFs.Position - dataStartPos);
|
||||
CompressedSize = (ulong)(_zipFs!.Position - dataStartPos);
|
||||
|
||||
#if NET20 || NET35 || NET40
|
||||
using (BinaryWriter zipBw = new(_zipFs, Encoding.UTF8))
|
||||
@@ -449,7 +449,7 @@ namespace Compress.gZip
|
||||
|
||||
if (ExtraData == null)
|
||||
{
|
||||
zipBw.Write(CRC); // 4 bytes
|
||||
zipBw.Write(CRC!); // 4 bytes
|
||||
zipBw.Write(UnCompressedSize); // 8 bytes
|
||||
}
|
||||
else
|
||||
@@ -468,7 +468,7 @@ namespace Compress.gZip
|
||||
|
||||
public ZipReturn ZipFileRollBack()
|
||||
{
|
||||
_zipFs.Position = dataStartPos;
|
||||
_zipFs!.Position = dataStartPos;
|
||||
return ZipReturn.ZipGood;
|
||||
}
|
||||
|
||||
@@ -490,17 +490,17 @@ namespace Compress.gZip
|
||||
return;
|
||||
}
|
||||
|
||||
_zipFs.Flush();
|
||||
_zipFs!.Flush();
|
||||
_zipFs.Close();
|
||||
_zipFs.Dispose();
|
||||
RVIO.File.Delete(_zipFileInfo.FullName);
|
||||
RVIO.File.Delete(_zipFileInfo!.FullName);
|
||||
_zipFileInfo = null;
|
||||
ZipOpen = ZipOpenType.Closed;
|
||||
}
|
||||
public ZipReturn GetRawStream(out Stream st)
|
||||
public ZipReturn GetRawStream(out Stream? st)
|
||||
{
|
||||
st = null;
|
||||
if (!RVIO.File.Exists(_zipFileInfo.FullName))
|
||||
if (!RVIO.File.Exists(_zipFileInfo!.FullName))
|
||||
{
|
||||
return ZipReturn.ZipErrorFileNotFound;
|
||||
}
|
||||
@@ -515,7 +515,7 @@ namespace Compress.gZip
|
||||
return ZipReturn.ZipErrorOpeningFile;
|
||||
}
|
||||
|
||||
st.Position = dataStartPos;
|
||||
st!.Position = dataStartPos;
|
||||
|
||||
return ZipReturn.ZipGood;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user