mirror of
https://github.com/SabreTools/SabreTools.IO.git
synced 2026-02-08 13:49:55 +00:00
Compare commits
11 Commits
1.8.0
...
split-test
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ef17819a3 | ||
|
|
b4d87e53a0 | ||
|
|
ae87869bb9 | ||
|
|
46ad576668 | ||
|
|
37b09b07a6 | ||
|
|
448e43dd05 | ||
|
|
e29b8ab4db | ||
|
|
6075aa25a2 | ||
|
|
c53fb33278 | ||
|
|
fb1fc5d85d | ||
|
|
2763d3915b |
80
.github/workflows/build_and_test.yml
vendored
80
.github/workflows/build_and_test.yml
vendored
@@ -1,48 +1,48 @@
|
||||
name: Build and Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
push:
|
||||
branches: ["main"]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: |
|
||||
6.0.x
|
||||
8.0.x
|
||||
9.0.x
|
||||
|
||||
- name: Run tests
|
||||
run: dotnet test
|
||||
|
||||
- name: Run publish script
|
||||
run: ./publish-nix.sh
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Update rolling tag
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git tag -f rolling
|
||||
git push origin :refs/tags/rolling || true
|
||||
git push origin rolling --force
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v5
|
||||
with:
|
||||
dotnet-version: |
|
||||
8.0.x
|
||||
9.0.x
|
||||
10.0.x
|
||||
|
||||
- name: Upload to rolling
|
||||
uses: ncipollo/release-action@v1.14.0
|
||||
with:
|
||||
allowUpdates: True
|
||||
artifacts: "*.nupkg,*.snupkg"
|
||||
body: 'Last built commit: ${{ github.sha }}'
|
||||
name: 'Rolling Release'
|
||||
prerelease: True
|
||||
replacesArtifacts: True
|
||||
tag: "rolling"
|
||||
updateOnlyUnreleased: True
|
||||
- name: Run tests
|
||||
run: dotnet test
|
||||
|
||||
- name: Run publish script
|
||||
run: ./publish-nix.sh
|
||||
|
||||
- name: Update rolling tag
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git tag -f rolling
|
||||
git push origin :refs/tags/rolling || true
|
||||
git push origin rolling --force
|
||||
|
||||
- name: Upload to rolling
|
||||
uses: ncipollo/release-action@v1.20.0
|
||||
with:
|
||||
allowUpdates: True
|
||||
artifacts: "*.nupkg,*.snupkg"
|
||||
body: "Last built commit: ${{ github.sha }}"
|
||||
name: "Rolling Release"
|
||||
prerelease: True
|
||||
replacesArtifacts: True
|
||||
tag: "rolling"
|
||||
updateOnlyUnreleased: True
|
||||
|
||||
34
.github/workflows/check_pr.yml
vendored
34
.github/workflows/check_pr.yml
vendored
@@ -3,21 +3,21 @@ name: Build PR
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: |
|
||||
6.0.x
|
||||
8.0.x
|
||||
9.0.x
|
||||
|
||||
- name: Build
|
||||
run: dotnet build
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Run tests
|
||||
run: dotnet test
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v5
|
||||
with:
|
||||
dotnet-version: |
|
||||
8.0.x
|
||||
9.0.x
|
||||
10.0.x
|
||||
|
||||
- name: Build
|
||||
run: dotnet build
|
||||
|
||||
- name: Run tests
|
||||
run: dotnet test
|
||||
|
||||
121
README.MD
121
README.MD
@@ -2,126 +2,7 @@
|
||||
|
||||
[](https://github.com/SabreTools/SabreTools.IO/actions/workflows/build_and_test.yml)
|
||||
|
||||
This library compries of I/O functionality used by other SabreTools projects.
|
||||
|
||||
Find the link to the Nuget package [here](https://www.nuget.org/packages/SabreTools.IO).
|
||||
|
||||
## Namespaces
|
||||
|
||||
Below are a list of the included namespaces and their overall utility.
|
||||
|
||||
### `SabreTools.IO`
|
||||
|
||||
Generic helper classes that involve custom functionality and utility.
|
||||
|
||||
### `SabreTools.IO.Compression`
|
||||
|
||||
Various compression implementations that are used across multiple projects. Most of the implementations are be ports of existing C and C++ code.
|
||||
|
||||
#### Supported Compressions
|
||||
|
||||
| Compression Name | Decompress | Compress | Notes |
|
||||
| --- | --- | --- | --- |
|
||||
| Blast | Yes | No | |
|
||||
| BZip2 | Yes | Yes | Sourced from DotNetZip |
|
||||
| Deflate | Yes | Yes | Sourced from DotNetZip |
|
||||
| LZ | Yes | No | KWAJ, QBasic 4.5, and SZDD variants; KWAJ incomplete |
|
||||
| LZX | No | No | |
|
||||
| MSZIP | Yes | No | |
|
||||
| Quantum | Yes* | No | Partial implementation based on standalone archives; not working |
|
||||
|
||||
**Note:** If something is marked with a `*` it means that it need testing.
|
||||
|
||||
#### External Libraries
|
||||
|
||||
| Library Name | Use |
|
||||
| --- | ---|
|
||||
| [DotNetZip](https://github.com/DinoChiesa/DotNetZip) | BZip2 and DEFLATE implementations; minor edits have been made |
|
||||
| [ZLibPort](https://github.com/Nanook/zlib-C-To-CSharp-Port) | Adds zlib code for internal and external use; minor edits have been made |
|
||||
|
||||
### `SabreTools.IO.Encryption`
|
||||
|
||||
Various encryption implementations that are used across multiple projects. Most of the implementations are be ports of existing C and C++ code.
|
||||
|
||||
#### Supported Encryption Schemes
|
||||
|
||||
| Encryption Scheme | Encrypt | Decrypt | Notes |
|
||||
| --- | --- | --- | --- |
|
||||
| AES/CTR | Yes | Yes | Subset of functionality exposed from [The Bouncy Castle Cryptography Library For .NET](https://github.com/bcgit/bc-csharp) |
|
||||
| MoPaQ | No | Yes | Used to encrypt and decrypt MoPaQ tables for processing |
|
||||
|
||||
### `SabreTools.IO.Extensions`
|
||||
|
||||
Extensions for `BinaryReader`, `byte[]`, and `Stream` to help with reading and writing various data types. Some data types are locked behind .NET version support.
|
||||
|
||||
This namespace also contains other various extensions that help with common functionality and safe access.
|
||||
|
||||
### `SabreTools.IO.Interfaces`
|
||||
|
||||
Common interfaces used mainly internal to the library.
|
||||
|
||||
| Interface | Notes |
|
||||
| --- | --- |
|
||||
| `IMatch<T>` | Represents a matcher for a generic type |
|
||||
| `IMatchSet<T, U>` | Represents a set of `IMatch<T>` types |
|
||||
|
||||
### `SabreTools.IO.Logging`
|
||||
|
||||
Logic for a logging system, including writing to console and textfile outputs. There are 4 possible log levels for logging statements to be invoked with. There is also a stopwatch implementation included for logging statements with automatic timespan tracking.
|
||||
|
||||
### `SabreTools.IO.Matching`
|
||||
|
||||
Classes designed to make matching contents and paths easier. These classes allow for both grouped and single matching as well as post-processing of matched information.
|
||||
|
||||
### `SabreTools.IO.Readers` and `SabreTools.IO.Writers`
|
||||
|
||||
Reading and writing support for the following file types:
|
||||
|
||||
- ClrMamePro-derived Metadata files
|
||||
- Standard and non-standard INI files
|
||||
- Separated-Value files (e.g. CSV, SSV, TSV)
|
||||
|
||||
For a generic INI implementation, see `SabreTools.IO.IniFile`.
|
||||
|
||||
### `SabreTools.IO.Streams`
|
||||
|
||||
Custom `Stream` implementations that are required for specialized use:
|
||||
|
||||
- `BufferedStream`: A format that is not a true stream implementation used for buffered, single-byte reads
|
||||
- `ReadOnlyBitStream`: A readonly stream implementation allowing bitwise reading
|
||||
- `ReadOnlyCompositeStream`: A readonly stream implementation that wraps multiple source streams in a set order
|
||||
- `ViewStream`: A readonly stream implementation representing a view into source data
|
||||
|
||||
### `SabreTools.IO.Transform`
|
||||
|
||||
File and stream implementations of common data transformations:
|
||||
|
||||
- Combine using either ordered concatenation or interleaving
|
||||
- Split by even/odd chunks or based on block size
|
||||
- Convert data either by bit-swapping, byte-swapping, word-swapping, or word/byte-swapping
|
||||
|
||||
### `SabreTools.Numerics`
|
||||
|
||||
Custom numeric types and related functionality.
|
||||
|
||||
#### Supported Numeric Types
|
||||
|
||||
| Type Name | Description |
|
||||
| --- | --- |
|
||||
| `BothInt8` | Both-endian `Int8` value |
|
||||
| `BothUInt8` | Both-endian `UInt8` value |
|
||||
| `BothInt16` | Both-endian `Int16` value |
|
||||
| `BothUInt16` | Both-endian `UInt16` value |
|
||||
| `BothInt32` | Both-endian `Int32` value |
|
||||
| `BothUInt32` | Both-endian `UInt32` value |
|
||||
| `BothInt64` | Both-endian `Int64` value |
|
||||
| `BothUInt64` | Both-endian `UInt64` value |
|
||||
|
||||
**Both-endian** or **bi-endian** numbers are represented by a little-endian value followed by a big-endian value, where both values are the same number.
|
||||
|
||||
### `SabreTools.Text.Compare`
|
||||
|
||||
Classes focused on string comparison by natural sorting. For example, "5" would be sorted before "100".
|
||||
This set of libraries enable special I/O-focused functionality used by other SabreTools projects. See the README files in each project directory for more details.
|
||||
|
||||
## Releases
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace SabreTools.IO.Test.Compression
|
||||
{
|
||||
string path = Path.Combine(Environment.CurrentDirectory, "TestData", "file-to-compress.bin");
|
||||
byte[] input = File.ReadAllBytes(path);
|
||||
MemoryStream output = new MemoryStream();
|
||||
var output = new MemoryStream();
|
||||
|
||||
var bzip = new BZip2OutputStream(output, leaveOpen: true);
|
||||
bzip.Write(input, 0, input.Length);
|
||||
@@ -38,4 +38,4 @@ namespace SabreTools.IO.Test.Compression
|
||||
Assert.Equal(122, output.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,4 +24,4 @@ namespace SabreTools.IO.Test.Compression
|
||||
Assert.Equal("AIAIAIAIAIAIA", str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ namespace SabreTools.IO.Test.Compression
|
||||
// CFDATA blocks.
|
||||
string path = Path.Combine(Environment.CurrentDirectory, "TestData", "test-archive.msz");
|
||||
byte[] inputBytes = File.ReadAllBytes(path);
|
||||
MemoryStream input = new MemoryStream(inputBytes);
|
||||
MemoryStream output = new MemoryStream();
|
||||
var input = new MemoryStream(inputBytes);
|
||||
var output = new MemoryStream();
|
||||
|
||||
var decompressor = Decompressor.Create();
|
||||
input.SeekIfPossible(0x0000);
|
||||
@@ -28,4 +28,4 @@ namespace SabreTools.IO.Test.Compression
|
||||
Assert.Equal(38470, output.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,4 +26,4 @@ namespace SabreTools.IO.Test.Compression
|
||||
Assert.Equal(38470, output.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -636,7 +636,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
[Fact]
|
||||
public void ReadDecimalBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(_decimalBytes.Reverse().ToArray());
|
||||
var stream = new MemoryStream([.. Enumerable.Reverse(_decimalBytes)]);
|
||||
var br = new BinaryReader(stream);
|
||||
decimal expected = 0.0123456789M;
|
||||
decimal read = br.ReadDecimalBigEndian();
|
||||
@@ -658,7 +658,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(_bytes);
|
||||
var br = new BinaryReader(stream);
|
||||
var expected = new Guid(_bytes.Reverse().ToArray());
|
||||
var expected = new Guid([.. Enumerable.Reverse(_bytes)]);
|
||||
Guid read = br.ReadGuidBigEndian();
|
||||
Assert.Equal(expected, read);
|
||||
}
|
||||
@@ -678,7 +678,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(_bytes);
|
||||
var br = new BinaryReader(stream);
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var reversed = Enumerable.Reverse(_bytes).ToArray();
|
||||
var expected = (Int128)new BigInteger(reversed);
|
||||
Int128 read = br.ReadInt128BigEndian();
|
||||
Assert.Equal(expected, read);
|
||||
@@ -699,7 +699,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(_bytes);
|
||||
var br = new BinaryReader(stream);
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var reversed = Enumerable.Reverse(_bytes).ToArray();
|
||||
var expected = (UInt128)new BigInteger(reversed);
|
||||
UInt128 read = br.ReadUInt128BigEndian();
|
||||
Assert.Equal(expected, read);
|
||||
@@ -780,14 +780,14 @@ namespace SabreTools.IO.Test.Extensions
|
||||
br = new BinaryReader(stream);
|
||||
Int128 expectedInt128 = (Int128)new BigInteger(_bytes);
|
||||
Int128 actualInt128 = br.ReadType<Int128>();
|
||||
Assert.Equal(expectedHalf, actualHalf);
|
||||
Assert.Equal(expectedInt128, actualInt128);
|
||||
|
||||
// UInt128
|
||||
stream = new MemoryStream(_bytes);
|
||||
br = new BinaryReader(stream);
|
||||
UInt128 expectedUInt128 = (UInt128)new BigInteger(_bytes);
|
||||
UInt128 actualUInt128 = br.ReadType<UInt128>();
|
||||
Assert.Equal(expectedHalf, actualHalf);
|
||||
Assert.Equal(expectedUInt128, actualUInt128);
|
||||
|
||||
// Enum
|
||||
stream = new MemoryStream(_bytes);
|
||||
@@ -1627,7 +1627,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
[Fact]
|
||||
public void PeekDecimalBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(_decimalBytes.Reverse().ToArray());
|
||||
var stream = new MemoryStream([.. Enumerable.Reverse(_decimalBytes)]);
|
||||
var br = new BinaryReader(stream);
|
||||
decimal expected = 0.0123456789M;
|
||||
decimal read = br.PeekDecimalBigEndian();
|
||||
@@ -1651,7 +1651,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(_bytes);
|
||||
var br = new BinaryReader(stream);
|
||||
var expected = new Guid(_bytes.Reverse().ToArray());
|
||||
var expected = new Guid([.. Enumerable.Reverse(_bytes)]);
|
||||
Guid read = br.PeekGuidBigEndian();
|
||||
Assert.Equal(expected, read);
|
||||
Assert.Equal(0, br.BaseStream.Position);
|
||||
@@ -1673,7 +1673,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(_bytes);
|
||||
var br = new BinaryReader(stream);
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var reversed = Enumerable.Reverse(_bytes).ToArray();
|
||||
var expected = (Int128)new BigInteger(reversed);
|
||||
Int128 read = br.PeekInt128BigEndian();
|
||||
Assert.Equal(expected, read);
|
||||
@@ -1696,7 +1696,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(_bytes);
|
||||
var br = new BinaryReader(stream);
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var reversed = Enumerable.Reverse(_bytes).ToArray();
|
||||
var expected = (UInt128)new BigInteger(reversed);
|
||||
UInt128 read = br.PeekUInt128BigEndian();
|
||||
Assert.Equal(expected, read);
|
||||
@@ -1908,7 +1908,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var br = new BinaryReader(stream);
|
||||
Half expected = BitConverter.Int16BitsToHalf(0x0100);
|
||||
bool actual = br.TryReadHalf(out Half read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -1919,7 +1918,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var br = new BinaryReader(stream);
|
||||
Half expected = BitConverter.Int16BitsToHalf(0x0001);
|
||||
bool actual = br.TryReadHalfBigEndian(out Half read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2113,7 +2111,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var br = new BinaryReader(stream);
|
||||
float expected = BitConverter.Int32BitsToSingle(0x03020100);
|
||||
bool actual = br.TryReadSingle(out float read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2124,7 +2121,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var br = new BinaryReader(stream);
|
||||
float expected = BitConverter.Int32BitsToSingle(0x00010203);
|
||||
bool actual = br.TryReadSingleBigEndian(out float read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2318,7 +2314,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var br = new BinaryReader(stream);
|
||||
double expected = BitConverter.Int64BitsToDouble(0x0706050403020100);
|
||||
bool actual = br.TryReadDouble(out double read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2329,7 +2324,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var br = new BinaryReader(stream);
|
||||
double expected = BitConverter.Int64BitsToDouble(0x0001020304050607);
|
||||
bool actual = br.TryReadDoubleBigEndian(out double read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2360,7 +2354,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var br = new BinaryReader(stream);
|
||||
var expected = new Guid(_bytes);
|
||||
bool actual = br.TryReadGuid(out Guid read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2371,7 +2364,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var br = new BinaryReader(stream);
|
||||
var expected = new Guid(_bytes.Reverse().ToArray());
|
||||
bool actual = br.TryReadGuidBigEndian(out Guid read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2382,7 +2374,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var br = new BinaryReader(stream);
|
||||
var expected = (Int128)new BigInteger(_bytes);
|
||||
bool actual = br.TryReadInt128(out Int128 read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2393,8 +2384,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var br = new BinaryReader(stream);
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var expected = (Int128)new BigInteger(reversed);
|
||||
bool actual = br.TryReadInt128BigEndian(out Int128 read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2405,7 +2394,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var br = new BinaryReader(stream);
|
||||
var expected = (UInt128)new BigInteger(_bytes);
|
||||
bool actual = br.TryReadUInt128(out UInt128 read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2416,8 +2404,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var br = new BinaryReader(stream);
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var expected = (UInt128)new BigInteger(reversed);
|
||||
bool actual = br.TryReadUInt128BigEndian(out UInt128 read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(1).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(1)];
|
||||
bw.Write((byte)0x00);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -43,7 +43,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
|
||||
int offset = 0;
|
||||
bw.WriteBothEndian(_bytes.ReadByteBothEndian(ref offset));
|
||||
@@ -55,7 +55,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bw.Write([0x00, 0x01, 0x02, 0x03]);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -65,7 +65,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bw.WriteBigEndian([0x03, 0x02, 0x01, 0x00]);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -75,7 +75,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(1).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(1)];
|
||||
bw.Write((sbyte)0x00);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -85,7 +85,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
|
||||
int offset = 0;
|
||||
bw.WriteBothEndian(_bytes.ReadSByteBothEndian(ref offset));
|
||||
@@ -97,7 +97,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(1).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(1)];
|
||||
bw.Write('\0');
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -117,7 +117,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bw.Write((short)0x0100);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -127,7 +127,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bool write = bw.WriteBigEndian((short)0x0001);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -138,7 +138,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
|
||||
int offset = 0;
|
||||
bw.WriteBothEndian(_bytes.ReadInt16BothEndian(ref offset));
|
||||
@@ -150,7 +150,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bw.Write((ushort)0x0100);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -160,7 +160,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bool write = bw.WriteBigEndian((ushort)0x0001);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -171,7 +171,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
|
||||
int offset = 0;
|
||||
bw.WriteBothEndian(_bytes.ReadUInt16BothEndian(ref offset));
|
||||
@@ -183,7 +183,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bw.Write(BitConverter.Int16BitsToHalf(0x0100));
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -193,7 +193,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bool write = bw.WriteBigEndian(BitConverter.Int16BitsToHalf(0x0001));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -204,7 +204,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(3).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(3)];
|
||||
bw.WriteAsInt24(0x020100);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -214,7 +214,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(3).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(3)];
|
||||
bool write = bw.WriteAsInt24BigEndian(0x000102);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -225,7 +225,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(3).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(3)];
|
||||
bw.WriteAsUInt24(0x020100);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -235,7 +235,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(3).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(3)];
|
||||
bool write = bw.WriteAsUInt24BigEndian(0x000102);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -246,7 +246,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bw.Write(0x03020100);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -256,7 +256,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = bw.WriteBigEndian(0x00010203);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -267,7 +267,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
|
||||
int offset = 0;
|
||||
bw.WriteBothEndian(_bytes.ReadInt32BothEndian(ref offset));
|
||||
@@ -279,7 +279,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bw.Write((uint)0x03020100);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -289,7 +289,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = bw.WriteBigEndian((uint)0x00010203);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -300,7 +300,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
|
||||
int offset = 0;
|
||||
bw.WriteBothEndian(_bytes.ReadUInt32BothEndian(ref offset));
|
||||
@@ -312,7 +312,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bw.Write(BitConverter.Int32BitsToSingle(0x03020100));
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -322,7 +322,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = bw.WriteBigEndian(BitConverter.Int32BitsToSingle(0x00010203));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -333,7 +333,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(6).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(6)];
|
||||
bw.WriteAsInt48(0x050403020100);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -343,7 +343,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(6).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(6)];
|
||||
bool write = bw.WriteAsInt48BigEndian(0x000102030405);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -354,7 +354,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(6).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(6)];
|
||||
bw.WriteAsUInt48(0x050403020100);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -364,7 +364,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(6).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(6)];
|
||||
bool write = bw.WriteAsUInt48BigEndian(0x000102030405);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -375,7 +375,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bw.Write(0x0706050403020100);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -385,7 +385,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bool write = bw.WriteBigEndian(0x0001020304050607);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -396,7 +396,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
|
||||
int offset = 0;
|
||||
bw.WriteBothEndian(_bytes.ReadInt64BothEndian(ref offset));
|
||||
@@ -408,7 +408,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bw.Write((ulong)0x0706050403020100);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -418,7 +418,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bool write = bw.WriteBigEndian((ulong)0x0001020304050607);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -429,7 +429,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
|
||||
int offset = 0;
|
||||
bw.WriteBothEndian(_bytes.ReadUInt64BothEndian(ref offset));
|
||||
@@ -441,7 +441,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bw.Write(BitConverter.Int64BitsToDouble(0x0706050403020100));
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -451,7 +451,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bool write = bw.WriteBigEndian(BitConverter.Int64BitsToDouble(0x0001020304050607));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -462,7 +462,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _decimalBytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _decimalBytes.Take(16)];
|
||||
bw.Write(0.0123456789M);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -472,7 +472,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _decimalBytes.Take(16).Reverse().ToArray();
|
||||
byte[] expected = [.. _decimalBytes.Take(16).Reverse()];
|
||||
bool write = bw.WriteBigEndian(0.0123456789M);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -483,7 +483,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = bw.Write(new Guid(_bytes));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -494,8 +494,8 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
bool write = bw.WriteBigEndian(new Guid(_bytes.Reverse().ToArray()));
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = bw.WriteBigEndian(new Guid([.. Enumerable.Reverse(_bytes)]));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -505,7 +505,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = bw.Write((Int128)new BigInteger(_bytes));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -516,8 +516,8 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
bool write = bw.WriteBigEndian((Int128)new BigInteger(_bytes.Reverse().ToArray()));
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = bw.WriteBigEndian((Int128)new BigInteger(Enumerable.Reverse(_bytes).ToArray()));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -527,7 +527,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = bw.Write((UInt128)new BigInteger(_bytes));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -538,8 +538,8 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
bool write = bw.WriteBigEndian((UInt128)new BigInteger(_bytes.Reverse().ToArray()));
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = bw.WriteBigEndian((UInt128)new BigInteger(Enumerable.Reverse(_bytes).ToArray()));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -672,7 +672,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
SecondValue = 0x07060504,
|
||||
FifthValue = "ABC",
|
||||
};
|
||||
byte[] expected = bytesWithString.Take(12).ToArray();
|
||||
byte[] expected = [.. bytesWithString.Take(12)];
|
||||
bool write = bw.WriteType(obj);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -697,7 +697,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
FourthValue = 0x0B0A,
|
||||
FifthValue = "ABC",
|
||||
};
|
||||
byte[] expected = bytesWithString.Take(16).ToArray();
|
||||
byte[] expected = [.. bytesWithString.Take(16)];
|
||||
bool write = bw.WriteType(obj);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
|
||||
@@ -36,6 +36,42 @@ namespace SabreTools.IO.Test.Extensions
|
||||
|
||||
#endregion
|
||||
|
||||
#region IsNumericArray
|
||||
|
||||
[Fact]
|
||||
public void IsNumericArray_Empty_False()
|
||||
{
|
||||
byte[] arr = [];
|
||||
bool actual = arr.IsNumericArray();
|
||||
Assert.False(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsNumericArray_NonNumeric_False()
|
||||
{
|
||||
byte[] arr = Encoding.ASCII.GetBytes("ABCDEF");
|
||||
bool actual = arr.IsNumericArray();
|
||||
Assert.False(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsNumericArray_MixedNumeric_False()
|
||||
{
|
||||
byte[] arr = Encoding.ASCII.GetBytes("ABC123");
|
||||
bool actual = arr.IsNumericArray();
|
||||
Assert.False(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsNumericArray_Numeric_True()
|
||||
{
|
||||
byte[] arr = Encoding.ASCII.GetBytes("0123456789");
|
||||
bool actual = arr.IsNumericArray();
|
||||
Assert.True(actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region FindAllPositions
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -550,7 +550,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
int offset = 0;
|
||||
decimal expected = 0.0123456789M;
|
||||
decimal read = _decimalBytes.Reverse().ToArray().ReadDecimalBigEndian(ref offset);
|
||||
decimal read = Enumerable.Reverse(_decimalBytes).ToArray().ReadDecimalBigEndian(ref offset);
|
||||
Assert.Equal(expected, read);
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void ReadGuidBigEndianTest()
|
||||
{
|
||||
int offset = 0;
|
||||
var expected = new Guid(_bytes.Reverse().ToArray());
|
||||
var expected = new Guid([.. Enumerable.Reverse(_bytes)]);
|
||||
Guid read = _bytes.ReadGuidBigEndian(ref offset);
|
||||
Assert.Equal(expected, read);
|
||||
}
|
||||
@@ -585,7 +585,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void ReadInt128BigEndianTest()
|
||||
{
|
||||
int offset = 0;
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var reversed = Enumerable.Reverse(_bytes).ToArray();
|
||||
var expected = (Int128)new BigInteger(reversed);
|
||||
Int128 read = _bytes.ReadInt128BigEndian(ref offset);
|
||||
Assert.Equal(expected, read);
|
||||
@@ -604,7 +604,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void ReadUInt128BigEndianTest()
|
||||
{
|
||||
int offset = 0;
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var reversed = Enumerable.Reverse(_bytes).ToArray();
|
||||
var expected = (UInt128)new BigInteger(reversed);
|
||||
UInt128 read = _bytes.ReadUInt128BigEndian(ref offset);
|
||||
Assert.Equal(expected, read);
|
||||
@@ -675,13 +675,13 @@ namespace SabreTools.IO.Test.Extensions
|
||||
offset = 0;
|
||||
Int128 expectedInt128 = (Int128)new BigInteger(_bytes);
|
||||
Int128 actualInt128 = _bytes.ReadType<Int128>(ref offset);
|
||||
Assert.Equal(expectedHalf, actualHalf);
|
||||
Assert.Equal(expectedInt128, actualInt128);
|
||||
|
||||
// UInt128
|
||||
offset = 0;
|
||||
UInt128 expectedUInt128 = (UInt128)new BigInteger(_bytes);
|
||||
UInt128 actualUInt128 = _bytes.ReadType<UInt128>(ref offset);
|
||||
Assert.Equal(expectedHalf, actualHalf);
|
||||
Assert.Equal(expectedUInt128, actualUInt128);
|
||||
|
||||
// Enum
|
||||
offset = 0;
|
||||
@@ -1473,7 +1473,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
int offset = 0;
|
||||
decimal expected = 0.0123456789M;
|
||||
decimal read = _decimalBytes.Reverse().ToArray().PeekDecimalBigEndian(ref offset);
|
||||
decimal read = Enumerable.Reverse(_decimalBytes).ToArray().PeekDecimalBigEndian(ref offset);
|
||||
Assert.Equal(expected, read);
|
||||
Assert.Equal(0, offset);
|
||||
}
|
||||
@@ -1492,7 +1492,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void PeekGuidBigEndianTest()
|
||||
{
|
||||
int offset = 0;
|
||||
var expected = new Guid(_bytes.Reverse().ToArray());
|
||||
var expected = new Guid([.. Enumerable.Reverse(_bytes)]);
|
||||
Guid read = _bytes.PeekGuidBigEndian(ref offset);
|
||||
Assert.Equal(expected, read);
|
||||
Assert.Equal(0, offset);
|
||||
@@ -1512,7 +1512,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void PeekInt128BigEndianTest()
|
||||
{
|
||||
int offset = 0;
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var reversed = Enumerable.Reverse(_bytes).ToArray();
|
||||
var expected = (Int128)new BigInteger(reversed);
|
||||
Int128 read = _bytes.PeekInt128BigEndian(ref offset);
|
||||
Assert.Equal(expected, read);
|
||||
@@ -1533,7 +1533,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void PeekUInt128BigEndianTest()
|
||||
{
|
||||
int offset = 0;
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var reversed = Enumerable.Reverse(_bytes).ToArray();
|
||||
var expected = (UInt128)new BigInteger(reversed);
|
||||
UInt128 read = _bytes.PeekUInt128BigEndian(ref offset);
|
||||
Assert.Equal(expected, read);
|
||||
@@ -1724,7 +1724,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadHalfTest()
|
||||
{
|
||||
int offset = 0;
|
||||
Half expected = BitConverter.Int16BitsToHalf(0x0100);
|
||||
bool actual = Array.Empty<byte>().TryReadHalf(ref offset, out Half read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -1734,7 +1733,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadHalfBigEndianTest()
|
||||
{
|
||||
int offset = 0;
|
||||
Half expected = BitConverter.Int16BitsToHalf(0x0001);
|
||||
bool actual = Array.Empty<byte>().TryReadHalfBigEndian(ref offset, out Half read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -1909,7 +1907,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadSingleTest()
|
||||
{
|
||||
int offset = 0;
|
||||
float expected = BitConverter.Int32BitsToSingle(0x03020100);
|
||||
bool actual = Array.Empty<byte>().TryReadSingle(ref offset, out float read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -1919,7 +1916,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadSingleBigEndianTest()
|
||||
{
|
||||
int offset = 0;
|
||||
float expected = BitConverter.Int32BitsToSingle(0x00010203);
|
||||
bool actual = Array.Empty<byte>().TryReadSingleBigEndian(ref offset, out float read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2094,7 +2090,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadDoubleTest()
|
||||
{
|
||||
int offset = 0;
|
||||
double expected = BitConverter.Int64BitsToDouble(0x0706050403020100);
|
||||
bool actual = Array.Empty<byte>().TryReadDouble(ref offset, out double read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2104,7 +2099,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadDoubleBigEndianTest()
|
||||
{
|
||||
int offset = 0;
|
||||
double expected = BitConverter.Int64BitsToDouble(0x0001020304050607);
|
||||
bool actual = Array.Empty<byte>().TryReadDoubleBigEndian(ref offset, out double read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2132,7 +2126,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadGuidTest()
|
||||
{
|
||||
int offset = 0;
|
||||
var expected = new Guid(_bytes);
|
||||
bool actual = Array.Empty<byte>().TryReadGuid(ref offset, out Guid read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2142,7 +2135,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadGuidBigEndianTest()
|
||||
{
|
||||
int offset = 0;
|
||||
var expected = new Guid(_bytes.Reverse().ToArray());
|
||||
bool actual = Array.Empty<byte>().TryReadGuidBigEndian(ref offset, out Guid read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2152,7 +2144,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadInt128Test()
|
||||
{
|
||||
int offset = 0;
|
||||
var expected = (Int128)new BigInteger(_bytes);
|
||||
bool actual = Array.Empty<byte>().TryReadInt128(ref offset, out Int128 read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2162,8 +2153,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadInt128BigEndianTest()
|
||||
{
|
||||
int offset = 0;
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var expected = (Int128)new BigInteger(reversed);
|
||||
bool actual = Array.Empty<byte>().TryReadInt128BigEndian(ref offset, out Int128 read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2173,7 +2162,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadUInt128Test()
|
||||
{
|
||||
int offset = 0;
|
||||
var expected = (UInt128)new BigInteger(_bytes);
|
||||
bool actual = Array.Empty<byte>().TryReadUInt128(ref offset, out UInt128 read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2183,8 +2171,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadUInt128BigEndianTest()
|
||||
{
|
||||
int offset = 0;
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var expected = (UInt128)new BigInteger(reversed);
|
||||
bool actual = Array.Empty<byte>().TryReadUInt128BigEndian(ref offset, out UInt128 read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(1).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(1)];
|
||||
bool write = buffer.Write(ref offset, (byte)0x00);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -43,7 +43,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
|
||||
int readOffset = 0;
|
||||
buffer.WriteBothEndian(ref offset, _bytes.ReadByteBothEndian(ref readOffset));
|
||||
@@ -55,7 +55,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = buffer.Write(ref offset, [0x00, 0x01, 0x02, 0x03]);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -66,7 +66,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = buffer.WriteBigEndian(ref offset, [0x03, 0x02, 0x01, 0x00]);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -77,7 +77,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(1).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(1)];
|
||||
bool write = buffer.Write(ref offset, (sbyte)0x00);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -88,7 +88,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
|
||||
int readOffset = 0;
|
||||
buffer.WriteBothEndian(ref offset, _bytes.ReadSByteBothEndian(ref readOffset));
|
||||
@@ -100,7 +100,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(1).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(1)];
|
||||
bool write = buffer.Write(ref offset, '\0');
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -122,7 +122,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bool write = buffer.Write(ref offset, (short)0x0100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -133,7 +133,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bool write = buffer.WriteBigEndian(ref offset, (short)0x0001);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -144,7 +144,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
|
||||
int readOffset = 0;
|
||||
buffer.WriteBothEndian(ref offset, _bytes.ReadInt16BothEndian(ref readOffset));
|
||||
@@ -156,7 +156,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bool write = buffer.Write(ref offset, (ushort)0x0100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -167,7 +167,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bool write = buffer.WriteBigEndian(ref offset, (ushort)0x0001);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -178,7 +178,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
|
||||
int readOffset = 0;
|
||||
buffer.WriteBothEndian(ref offset, _bytes.ReadUInt16BothEndian(ref readOffset));
|
||||
@@ -190,7 +190,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bool write = buffer.Write(ref offset, BitConverter.Int16BitsToHalf(0x0100));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -201,7 +201,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bool write = buffer.WriteBigEndian(ref offset, BitConverter.Int16BitsToHalf(0x0001));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -212,7 +212,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(3).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(3)];
|
||||
bool write = buffer.WriteAsInt24(ref offset, 0x020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -223,7 +223,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(3).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(3)];
|
||||
bool write = buffer.WriteAsInt24BigEndian(ref offset, 0x000102);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -234,7 +234,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(3).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(3)];
|
||||
bool write = buffer.WriteAsUInt24(ref offset, 0x020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -245,7 +245,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(3).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(3)];
|
||||
bool write = buffer.WriteAsUInt24BigEndian(ref offset, 0x000102);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -256,7 +256,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = buffer.Write(ref offset, 0x03020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -267,7 +267,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = buffer.WriteBigEndian(ref offset, 0x00010203);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -278,7 +278,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
|
||||
int readOffset = 0;
|
||||
buffer.WriteBothEndian(ref offset, _bytes.ReadInt32BothEndian(ref readOffset));
|
||||
@@ -290,7 +290,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = buffer.Write(ref offset, (uint)0x03020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -301,7 +301,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = buffer.WriteBigEndian(ref offset, (uint)0x00010203);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -312,7 +312,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
|
||||
int readOffset = 0;
|
||||
buffer.WriteBothEndian(ref offset, _bytes.ReadUInt32BothEndian(ref readOffset));
|
||||
@@ -324,7 +324,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = buffer.Write(ref offset, BitConverter.Int32BitsToSingle(0x03020100));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -335,7 +335,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = buffer.WriteBigEndian(ref offset, BitConverter.Int32BitsToSingle(0x00010203));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -346,7 +346,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(6).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(6)];
|
||||
bool write = buffer.WriteAsInt48(ref offset, 0x050403020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -357,7 +357,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(6).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(6)];
|
||||
bool write = buffer.WriteAsInt48BigEndian(ref offset, 0x000102030405);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -368,7 +368,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(6).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(6)];
|
||||
bool write = buffer.WriteAsUInt48(ref offset, 0x050403020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -379,7 +379,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(6).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(6)];
|
||||
bool write = buffer.WriteAsUInt48BigEndian(ref offset, 0x000102030405);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -390,7 +390,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bool write = buffer.Write(ref offset, 0x0706050403020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -401,7 +401,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bool write = buffer.WriteBigEndian(ref offset, 0x0001020304050607);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -412,7 +412,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
|
||||
int readOffset = 0;
|
||||
buffer.WriteBothEndian(ref offset, _bytes.ReadInt64BothEndian(ref readOffset));
|
||||
@@ -424,7 +424,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bool write = buffer.Write(ref offset, (ulong)0x0706050403020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -435,7 +435,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bool write = buffer.WriteBigEndian(ref offset, (ulong)0x0001020304050607);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -446,7 +446,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
|
||||
int readOffset = 0;
|
||||
buffer.WriteBothEndian(ref offset, _bytes.ReadUInt64BothEndian(ref readOffset));
|
||||
@@ -458,7 +458,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bool write = buffer.Write(ref offset, BitConverter.Int64BitsToDouble(0x0706050403020100));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -469,7 +469,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bool write = buffer.WriteBigEndian(ref offset, BitConverter.Int64BitsToDouble(0x0001020304050607));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -480,7 +480,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _decimalBytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _decimalBytes.Take(16)];
|
||||
bool write = buffer.Write(ref offset, 0.0123456789M);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -491,7 +491,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _decimalBytes.Take(16).Reverse().ToArray();
|
||||
byte[] expected = [.. _decimalBytes.Take(16).Reverse()];
|
||||
bool write = buffer.WriteBigEndian(ref offset, 0.0123456789M);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -502,7 +502,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = buffer.Write(ref offset, new Guid(_bytes));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -513,8 +513,8 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
bool write = buffer.WriteBigEndian(ref offset, new Guid(_bytes.Reverse().ToArray()));
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = buffer.WriteBigEndian(ref offset, new Guid([.. Enumerable.Reverse(_bytes)]));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
}
|
||||
@@ -524,7 +524,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = buffer.Write(ref offset, (Int128)new BigInteger(_bytes));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -535,8 +535,8 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
bool write = buffer.WriteBigEndian(ref offset, (Int128)new BigInteger(_bytes.Reverse().ToArray()));
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = buffer.WriteBigEndian(ref offset, (Int128)new BigInteger(Enumerable.Reverse(_bytes).ToArray()));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
}
|
||||
@@ -546,7 +546,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = buffer.Write(ref offset, (UInt128)new BigInteger(_bytes));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -557,8 +557,8 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
byte[] buffer = new byte[16];
|
||||
int offset = 0;
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
bool write = buffer.WriteBigEndian(ref offset, (UInt128)new BigInteger(_bytes.Reverse().ToArray()));
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = buffer.WriteBigEndian(ref offset, (UInt128)new BigInteger(Enumerable.Reverse(_bytes).ToArray()));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
}
|
||||
@@ -691,7 +691,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
SecondValue = 0x07060504,
|
||||
FifthValue = "ABC",
|
||||
};
|
||||
byte[] expected = bytesWithString.Take(12).ToArray();
|
||||
byte[] expected = [.. bytesWithString.Take(12)];
|
||||
bool write = buffer.WriteType(ref offset, obj);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
@@ -716,7 +716,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
FourthValue = 0x0B0A,
|
||||
FifthValue = "ABC",
|
||||
};
|
||||
byte[] expected = bytesWithString.Take(16).ToArray();
|
||||
byte[] expected = [.. bytesWithString.Take(16)];
|
||||
bool write = buffer.WriteType(ref offset, obj);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, buffer);
|
||||
|
||||
86
SabreTools.IO.Test/Extensions/DictionaryExtensionsTests.cs
Normal file
86
SabreTools.IO.Test/Extensions/DictionaryExtensionsTests.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System.Collections.Generic;
|
||||
using SabreTools.IO.Extensions;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
public class DictionaryExtensionsTests
|
||||
{
|
||||
#region MergeWith
|
||||
|
||||
[Fact]
|
||||
public void MergeWith_EmptySource_EmptyOther_Empty()
|
||||
{
|
||||
Dictionary<string, List<string>> source = [];
|
||||
Dictionary<string, List<string>> other = [];
|
||||
|
||||
source.MergeWith(other);
|
||||
Assert.Empty(source);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MergeWith_EmptySource_EmptyKeyOther_Empty()
|
||||
{
|
||||
Dictionary<string, List<string>> source = [];
|
||||
Dictionary<string, List<string>> other = [];
|
||||
other.Add("key", []);
|
||||
|
||||
source.MergeWith(other);
|
||||
Assert.Empty(source);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MergeWith_EmptySource_FilledOther_Filled()
|
||||
{
|
||||
Dictionary<string, List<string>> source = [];
|
||||
Dictionary<string, List<string>> other = [];
|
||||
other.Add("key", ["value"]);
|
||||
|
||||
source.MergeWith(other);
|
||||
string key = Assert.Single(source.Keys);
|
||||
Assert.Equal("key", key);
|
||||
List<string> actual = source[key];
|
||||
string value = Assert.Single(actual);
|
||||
Assert.Equal("value", value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MergeWith_FilledSource_EmptyOther_Filled()
|
||||
{
|
||||
Dictionary<string, List<string>> source = [];
|
||||
source.Add("key", ["value"]);
|
||||
Dictionary<string, List<string>> other = [];
|
||||
|
||||
source.MergeWith(other);
|
||||
string key = Assert.Single(source.Keys);
|
||||
Assert.Equal("key", key);
|
||||
List<string> actual = source[key];
|
||||
string value = Assert.Single(actual);
|
||||
Assert.Equal("value", value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MergeWith_FilledSource_FilledOther_Filled()
|
||||
{
|
||||
Dictionary<string, List<string>> source = [];
|
||||
source.Add("key1", ["value1"]);
|
||||
Dictionary<string, List<string>> other = [];
|
||||
other.Add("key2", ["value2"]);
|
||||
|
||||
source.MergeWith(other);
|
||||
Assert.Equal(2, source.Keys.Count);
|
||||
|
||||
Assert.Contains("key1", source.Keys);
|
||||
List<string> actualKey1 = source["key1"];
|
||||
string value1 = Assert.Single(actualKey1);
|
||||
Assert.Equal("value1", value1);
|
||||
|
||||
Assert.Contains("key2", source.Keys);
|
||||
List<string> actualKey2 = source["key2"];
|
||||
string value2 = Assert.Single(actualKey2);
|
||||
Assert.Equal("value2", value2);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Fake enumerable that uses <see cref="ErrorEnumerator"/>
|
||||
/// Fake enumerable that uses <see cref="ErrorEnumerator"/>
|
||||
/// </summary>
|
||||
private class ErrorEnumerable : IEnumerable<string>
|
||||
{
|
||||
|
||||
@@ -323,7 +323,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
long actual = stream.SeekIfPossible(0, origin);
|
||||
Assert.Equal(8, actual);
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[InlineData(SeekOrigin.Begin)]
|
||||
[InlineData(SeekOrigin.Current)]
|
||||
@@ -334,7 +334,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
long actual = stream.SeekIfPossible(0, origin);
|
||||
Assert.Equal(-1, actual);
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[InlineData(SeekOrigin.Begin)]
|
||||
[InlineData(SeekOrigin.Current)]
|
||||
@@ -345,7 +345,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
long actual = stream.SeekIfPossible(0, origin);
|
||||
Assert.Equal(-1, actual);
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[InlineData(SeekOrigin.Begin, 5, 5)]
|
||||
[InlineData(SeekOrigin.Current, 5, 7)]
|
||||
|
||||
@@ -552,7 +552,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
[Fact]
|
||||
public void ReadDecimalBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(_decimalBytes.Reverse().ToArray());
|
||||
var stream = new MemoryStream([.. Enumerable.Reverse(_decimalBytes)]);
|
||||
decimal expected = 0.0123456789M;
|
||||
decimal read = stream.ReadDecimalBigEndian();
|
||||
Assert.Equal(expected, read);
|
||||
@@ -571,7 +571,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void ReadGuidBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(_bytes);
|
||||
var expected = new Guid(_bytes.Reverse().ToArray());
|
||||
var expected = new Guid([.. Enumerable.Reverse(_bytes)]);
|
||||
Guid read = stream.ReadGuidBigEndian();
|
||||
Assert.Equal(expected, read);
|
||||
}
|
||||
@@ -589,7 +589,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void ReadInt128BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(_bytes);
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var reversed = Enumerable.Reverse(_bytes).ToArray();
|
||||
var expected = (Int128)new BigInteger(reversed);
|
||||
Int128 read = stream.ReadInt128BigEndian();
|
||||
Assert.Equal(expected, read);
|
||||
@@ -608,7 +608,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void ReadUInt128BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(_bytes);
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var reversed = Enumerable.Reverse(_bytes).ToArray();
|
||||
var expected = (UInt128)new BigInteger(reversed);
|
||||
UInt128 read = stream.ReadUInt128BigEndian();
|
||||
Assert.Equal(expected, read);
|
||||
@@ -679,13 +679,13 @@ namespace SabreTools.IO.Test.Extensions
|
||||
stream = new MemoryStream(_bytes);
|
||||
Int128 expectedInt128 = (Int128)new BigInteger(_bytes);
|
||||
Int128 actualInt128 = stream.ReadType<Int128>();
|
||||
Assert.Equal(expectedHalf, actualHalf);
|
||||
Assert.Equal(expectedInt128, actualInt128);
|
||||
|
||||
// UInt128
|
||||
stream = new MemoryStream(_bytes);
|
||||
UInt128 expectedUInt128 = (UInt128)new BigInteger(_bytes);
|
||||
UInt128 actualUInt128 = stream.ReadType<UInt128>();
|
||||
Assert.Equal(expectedHalf, actualHalf);
|
||||
Assert.Equal(expectedUInt128, actualUInt128);
|
||||
|
||||
// Enum
|
||||
stream = new MemoryStream(_bytes);
|
||||
@@ -1467,7 +1467,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
[Fact]
|
||||
public void PeekDecimalBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(_decimalBytes.Reverse().ToArray());
|
||||
var stream = new MemoryStream([.. Enumerable.Reverse(_decimalBytes)]);
|
||||
decimal expected = 0.0123456789M;
|
||||
decimal read = stream.PeekDecimalBigEndian();
|
||||
Assert.Equal(expected, read);
|
||||
@@ -1488,7 +1488,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void PeekGuidBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(_bytes);
|
||||
var expected = new Guid(_bytes.Reverse().ToArray());
|
||||
var expected = new Guid([.. Enumerable.Reverse(_bytes)]);
|
||||
Guid read = stream.PeekGuidBigEndian();
|
||||
Assert.Equal(expected, read);
|
||||
Assert.Equal(0, stream.Position);
|
||||
@@ -1508,7 +1508,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void PeekInt128BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(_bytes);
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var reversed = Enumerable.Reverse(_bytes).ToArray();
|
||||
var expected = (Int128)new BigInteger(reversed);
|
||||
Int128 read = stream.PeekInt128BigEndian();
|
||||
Assert.Equal(expected, read);
|
||||
@@ -1529,7 +1529,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void PeekUInt128BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(_bytes);
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var reversed = Enumerable.Reverse(_bytes).ToArray();
|
||||
var expected = (UInt128)new BigInteger(reversed);
|
||||
UInt128 read = stream.PeekUInt128BigEndian();
|
||||
Assert.Equal(expected, read);
|
||||
@@ -1712,7 +1712,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadHalfTest()
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
Half expected = BitConverter.Int16BitsToHalf(0x0100);
|
||||
bool actual = stream.TryReadHalf(out Half read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -1722,7 +1721,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadHalfBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
Half expected = BitConverter.Int16BitsToHalf(0x0001);
|
||||
bool actual = stream.TryReadHalfBigEndian(out Half read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -1897,7 +1895,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadSingleTest()
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
float expected = BitConverter.Int32BitsToSingle(0x03020100);
|
||||
bool actual = stream.TryReadSingle(out float read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -1907,7 +1904,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadSingleBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
float expected = BitConverter.Int32BitsToSingle(0x00010203);
|
||||
bool actual = stream.TryReadSingleBigEndian(out float read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2082,7 +2078,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadDoubleTest()
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
double expected = BitConverter.Int64BitsToDouble(0x0706050403020100);
|
||||
bool actual = stream.TryReadDouble(out double read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2092,7 +2087,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadDoubleBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
double expected = BitConverter.Int64BitsToDouble(0x0001020304050607);
|
||||
bool actual = stream.TryReadDoubleBigEndian(out double read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2120,7 +2114,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadGuidTest()
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var expected = new Guid(_bytes);
|
||||
bool actual = stream.TryReadGuid(out Guid read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2130,7 +2123,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadGuidBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var expected = new Guid(_bytes.Reverse().ToArray());
|
||||
bool actual = stream.TryReadGuidBigEndian(out Guid read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2140,7 +2132,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadInt128Test()
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var expected = (Int128)new BigInteger(_bytes);
|
||||
bool actual = stream.TryReadInt128(out Int128 read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2150,8 +2141,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadInt128BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var expected = (Int128)new BigInteger(reversed);
|
||||
bool actual = stream.TryReadInt128BigEndian(out Int128 read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2161,7 +2150,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadUInt128Test()
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var expected = (UInt128)new BigInteger(_bytes);
|
||||
bool actual = stream.TryReadUInt128(out UInt128 read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
@@ -2171,8 +2159,6 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void TryReadUInt128BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream([]);
|
||||
var reversed = _bytes.Reverse().ToArray();
|
||||
var expected = (UInt128)new BigInteger(reversed);
|
||||
bool actual = stream.TryReadUInt128BigEndian(out UInt128 read);
|
||||
Assert.False(actual);
|
||||
Assert.Equal(default, read);
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteByteValueTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(1).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(1)];
|
||||
bool write = stream.Write((byte)0x00);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -42,7 +42,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteByteBothEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
|
||||
int offset = 0;
|
||||
stream.WriteBothEndian(_bytes.ReadByteBothEndian(ref offset));
|
||||
@@ -53,7 +53,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteBytesTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = StreamWriterExtensions.Write(stream, [0x00, 0x01, 0x02, 0x03]);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -63,7 +63,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteBytesBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
stream.WriteBigEndian([0x03, 0x02, 0x01, 0x00]);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -72,7 +72,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteSByteTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(1).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(1)];
|
||||
bool write = stream.Write((sbyte)0x00);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -82,7 +82,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteSByteBothEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
|
||||
int offset = 0;
|
||||
stream.WriteBothEndian(_bytes.ReadSByteBothEndian(ref offset));
|
||||
@@ -93,7 +93,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteCharTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(1).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(1)];
|
||||
bool write = stream.Write('\0');
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -112,7 +112,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteInt16Test()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bool write = stream.Write((short)0x0100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -122,7 +122,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteInt16BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bool write = stream.WriteBigEndian((short)0x0001);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -132,7 +132,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteInt16BothEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
|
||||
int offset = 0;
|
||||
stream.WriteBothEndian(_bytes.ReadInt16BothEndian(ref offset));
|
||||
@@ -143,7 +143,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteUInt16Test()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bool write = stream.Write((ushort)0x0100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -153,7 +153,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteUInt16BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bool write = stream.WriteBigEndian((ushort)0x0001);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -163,7 +163,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteUInt16BothEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
|
||||
int offset = 0;
|
||||
stream.WriteBothEndian(_bytes.ReadUInt16BothEndian(ref offset));
|
||||
@@ -174,7 +174,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteHalfTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bool write = stream.Write(BitConverter.Int16BitsToHalf(0x0100));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -184,7 +184,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteHalfBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(2).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(2)];
|
||||
bool write = stream.WriteBigEndian(BitConverter.Int16BitsToHalf(0x0001));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -194,7 +194,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteInt24Test()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(3).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(3)];
|
||||
bool write = stream.WriteAsInt24(0x020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -204,7 +204,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteInt24BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(3).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(3)];
|
||||
bool write = stream.WriteAsInt24BigEndian(0x000102);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -214,7 +214,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteUInt24Test()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(3).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(3)];
|
||||
bool write = stream.WriteAsUInt24(0x020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -224,7 +224,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteUInt24BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(3).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(3)];
|
||||
bool write = stream.WriteAsUInt24BigEndian(0x000102);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -234,7 +234,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteInt32Test()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = stream.Write(0x03020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -244,7 +244,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteInt32BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = stream.WriteBigEndian(0x00010203);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -254,7 +254,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteInt32BothEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
|
||||
int offset = 0;
|
||||
stream.WriteBothEndian(_bytes.ReadInt32BothEndian(ref offset));
|
||||
@@ -265,7 +265,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteUInt32Test()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = stream.Write((uint)0x03020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -275,7 +275,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteUInt32BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = stream.WriteBigEndian((uint)0x00010203);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -285,7 +285,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteUInt32BothEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
|
||||
int offset = 0;
|
||||
stream.WriteBothEndian(_bytes.ReadUInt32BothEndian(ref offset));
|
||||
@@ -296,7 +296,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteSingleTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = stream.Write(BitConverter.Int32BitsToSingle(0x03020100));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -306,7 +306,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteSingleBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(4).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(4)];
|
||||
bool write = stream.WriteBigEndian(BitConverter.Int32BitsToSingle(0x00010203));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -316,7 +316,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteInt48Test()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(6).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(6)];
|
||||
bool write = stream.WriteAsInt48(0x050403020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -326,7 +326,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteInt48BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(6).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(6)];
|
||||
bool write = stream.WriteAsInt48BigEndian(0x000102030405);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -336,7 +336,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteUInt48Test()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(6).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(6)];
|
||||
bool write = stream.WriteAsUInt48(0x050403020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -346,7 +346,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteUInt48BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(6).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(6)];
|
||||
bool write = stream.WriteAsUInt48BigEndian(0x000102030405);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -356,7 +356,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteInt64Test()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bool write = stream.Write(0x0706050403020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -366,7 +366,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteInt64BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bool write = stream.WriteBigEndian(0x0001020304050607);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -376,7 +376,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteInt64BothEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
|
||||
int offset = 0;
|
||||
stream.WriteBothEndian(_bytes.ReadInt64BothEndian(ref offset));
|
||||
@@ -387,7 +387,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteUInt64Test()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bool write = stream.Write((ulong)0x0706050403020100);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -397,7 +397,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteUInt64BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bool write = stream.WriteBigEndian((ulong)0x0001020304050607);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -407,7 +407,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteUInt64BothEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
|
||||
int offset = 0;
|
||||
stream.WriteBothEndian(_bytes.ReadUInt64BothEndian(ref offset));
|
||||
@@ -418,7 +418,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteDoubleTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bool write = stream.Write(BitConverter.Int64BitsToDouble(0x0706050403020100));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -428,7 +428,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteDoubleBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(8).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(8)];
|
||||
bool write = stream.WriteBigEndian(BitConverter.Int64BitsToDouble(0x0001020304050607));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -438,7 +438,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteDecimalTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _decimalBytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _decimalBytes.Take(16)];
|
||||
bool write = stream.Write(0.0123456789M);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -448,7 +448,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteDecimalBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _decimalBytes.Take(16).Reverse().ToArray();
|
||||
byte[] expected = [.. _decimalBytes.Take(16).Reverse()];
|
||||
bool write = stream.WriteBigEndian(0.0123456789M);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -458,7 +458,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteGuidTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = stream.Write(new Guid(_bytes));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -468,8 +468,8 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteGuidBigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
bool write = stream.WriteBigEndian(new Guid(_bytes.Reverse().ToArray()));
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = stream.WriteBigEndian(new Guid([.. Enumerable.Reverse(_bytes)]));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -478,7 +478,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteInt128Test()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = stream.Write((Int128)new BigInteger(_bytes));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -488,8 +488,8 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteInt128BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
bool write = stream.WriteBigEndian((Int128)new BigInteger(_bytes.Reverse().ToArray()));
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = stream.WriteBigEndian((Int128)new BigInteger(Enumerable.Reverse(_bytes).ToArray()));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -498,7 +498,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteUInt128Test()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = stream.Write((UInt128)new BigInteger(_bytes));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -508,8 +508,8 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public void WriteUInt128BigEndianTest()
|
||||
{
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
byte[] expected = _bytes.Take(16).ToArray();
|
||||
bool write = stream.WriteBigEndian((UInt128)new BigInteger(_bytes.Reverse().ToArray()));
|
||||
byte[] expected = [.. _bytes.Take(16)];
|
||||
bool write = stream.WriteBigEndian((UInt128)new BigInteger(Enumerable.Reverse(_bytes).ToArray()));
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
}
|
||||
@@ -630,7 +630,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
SecondValue = 0x07060504,
|
||||
FifthValue = "ABC",
|
||||
};
|
||||
byte[] expected = bytesWithString.Take(12).ToArray();
|
||||
byte[] expected = [.. bytesWithString.Take(12)];
|
||||
bool write = stream.WriteType(obj);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
@@ -654,7 +654,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
FourthValue = 0x0B0A,
|
||||
FifthValue = "ABC",
|
||||
};
|
||||
byte[] expected = bytesWithString.Take(16).ToArray();
|
||||
byte[] expected = [.. bytesWithString.Take(16)];
|
||||
bool write = stream.WriteType(obj);
|
||||
Assert.True(write);
|
||||
ValidateBytes(expected, stream.GetBuffer());
|
||||
|
||||
@@ -73,4 +73,4 @@ namespace SabreTools.IO.Test.Extensions
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public TestStructPoint[]? StructArray;
|
||||
|
||||
/// <summary>
|
||||
/// Length of <see cref="LPByteArray"/>
|
||||
/// Length of <see cref="LPByteArray"/>
|
||||
/// </summary>
|
||||
public ushort LPByteArrayLength;
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)]
|
||||
public byte[]? LPByteArray;
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 4 entry nested byte array
|
||||
// /// </summary>
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
|
||||
public uint FieldB;
|
||||
}
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
internal class TestStructInheritanceChild2 : TestStructInheritanceParent
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace SabreTools.IO.Test.Extensions
|
||||
public int SecondValue;
|
||||
|
||||
public ushort ThirdValue;
|
||||
|
||||
|
||||
public short FourthValue;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
|
||||
@@ -5,7 +5,7 @@ using Xunit;
|
||||
namespace SabreTools.IO.Test.Matching
|
||||
{
|
||||
/// <remarks>
|
||||
/// All other test cases are covered by <see cref="PathMatchTests"/>
|
||||
/// All other test cases are covered by <see cref="PathMatchTests"/>
|
||||
/// </remarks>
|
||||
public class FilePathMatchTests
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
|
||||
<IsPackable>false</IsPackable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
@@ -24,7 +24,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
@@ -37,4 +37,4 @@ namespace SabreTools.IO.Test.Streams
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,4 +415,4 @@ namespace SabreTools.IO.Test.Streams
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,22 +7,98 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreTools.IO", "SabreTools
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreTools.IO.Test", "SabreTools.IO.Test\SabreTools.IO.Test.csproj", "{A9767735-5042-48A1-849C-96035DB1DD53}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreTools.Text", "SabreTools.Text\SabreTools.Text.csproj", "{EC8FD8AD-579F-4B8B-A65E-119E5294ADC1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreTools.Numerics", "SabreTools.Numerics\SabreTools.Numerics.csproj", "{565EAC34-B533-4C5C-9B81-77AE4B33A027}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreTools.Numerics.Test", "SabreTools.Numerics.Test\SabreTools.Numerics.Test.csproj", "{35F068EF-A652-4435-8890-1E6239EEBEFB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreTools.Text.Test", "SabreTools.Text.Test\SabreTools.Text.Test.csproj", "{71513020-B588-4A66-8122-E1639A39B8A8}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{87CE4411-80D9-49FF-894C-761F1C20D9A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{87CE4411-80D9-49FF-894C-761F1C20D9A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{87CE4411-80D9-49FF-894C-761F1C20D9A5}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{87CE4411-80D9-49FF-894C-761F1C20D9A5}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{87CE4411-80D9-49FF-894C-761F1C20D9A5}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{87CE4411-80D9-49FF-894C-761F1C20D9A5}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{87CE4411-80D9-49FF-894C-761F1C20D9A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{87CE4411-80D9-49FF-894C-761F1C20D9A5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{87CE4411-80D9-49FF-894C-761F1C20D9A5}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{87CE4411-80D9-49FF-894C-761F1C20D9A5}.Release|x64.Build.0 = Release|Any CPU
|
||||
{87CE4411-80D9-49FF-894C-761F1C20D9A5}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{87CE4411-80D9-49FF-894C-761F1C20D9A5}.Release|x86.Build.0 = Release|Any CPU
|
||||
{A9767735-5042-48A1-849C-96035DB1DD53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A9767735-5042-48A1-849C-96035DB1DD53}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A9767735-5042-48A1-849C-96035DB1DD53}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{A9767735-5042-48A1-849C-96035DB1DD53}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{A9767735-5042-48A1-849C-96035DB1DD53}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{A9767735-5042-48A1-849C-96035DB1DD53}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{A9767735-5042-48A1-849C-96035DB1DD53}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A9767735-5042-48A1-849C-96035DB1DD53}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A9767735-5042-48A1-849C-96035DB1DD53}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{A9767735-5042-48A1-849C-96035DB1DD53}.Release|x64.Build.0 = Release|Any CPU
|
||||
{A9767735-5042-48A1-849C-96035DB1DD53}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{A9767735-5042-48A1-849C-96035DB1DD53}.Release|x86.Build.0 = Release|Any CPU
|
||||
{EC8FD8AD-579F-4B8B-A65E-119E5294ADC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EC8FD8AD-579F-4B8B-A65E-119E5294ADC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EC8FD8AD-579F-4B8B-A65E-119E5294ADC1}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{EC8FD8AD-579F-4B8B-A65E-119E5294ADC1}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{EC8FD8AD-579F-4B8B-A65E-119E5294ADC1}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{EC8FD8AD-579F-4B8B-A65E-119E5294ADC1}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{EC8FD8AD-579F-4B8B-A65E-119E5294ADC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EC8FD8AD-579F-4B8B-A65E-119E5294ADC1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EC8FD8AD-579F-4B8B-A65E-119E5294ADC1}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{EC8FD8AD-579F-4B8B-A65E-119E5294ADC1}.Release|x64.Build.0 = Release|Any CPU
|
||||
{EC8FD8AD-579F-4B8B-A65E-119E5294ADC1}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{EC8FD8AD-579F-4B8B-A65E-119E5294ADC1}.Release|x86.Build.0 = Release|Any CPU
|
||||
{565EAC34-B533-4C5C-9B81-77AE4B33A027}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{565EAC34-B533-4C5C-9B81-77AE4B33A027}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{565EAC34-B533-4C5C-9B81-77AE4B33A027}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{565EAC34-B533-4C5C-9B81-77AE4B33A027}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{565EAC34-B533-4C5C-9B81-77AE4B33A027}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{565EAC34-B533-4C5C-9B81-77AE4B33A027}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{565EAC34-B533-4C5C-9B81-77AE4B33A027}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{565EAC34-B533-4C5C-9B81-77AE4B33A027}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{565EAC34-B533-4C5C-9B81-77AE4B33A027}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{565EAC34-B533-4C5C-9B81-77AE4B33A027}.Release|x64.Build.0 = Release|Any CPU
|
||||
{565EAC34-B533-4C5C-9B81-77AE4B33A027}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{565EAC34-B533-4C5C-9B81-77AE4B33A027}.Release|x86.Build.0 = Release|Any CPU
|
||||
{35F068EF-A652-4435-8890-1E6239EEBEFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{35F068EF-A652-4435-8890-1E6239EEBEFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{35F068EF-A652-4435-8890-1E6239EEBEFB}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{35F068EF-A652-4435-8890-1E6239EEBEFB}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{35F068EF-A652-4435-8890-1E6239EEBEFB}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{35F068EF-A652-4435-8890-1E6239EEBEFB}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{35F068EF-A652-4435-8890-1E6239EEBEFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{35F068EF-A652-4435-8890-1E6239EEBEFB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{35F068EF-A652-4435-8890-1E6239EEBEFB}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{35F068EF-A652-4435-8890-1E6239EEBEFB}.Release|x64.Build.0 = Release|Any CPU
|
||||
{35F068EF-A652-4435-8890-1E6239EEBEFB}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{35F068EF-A652-4435-8890-1E6239EEBEFB}.Release|x86.Build.0 = Release|Any CPU
|
||||
{71513020-B588-4A66-8122-E1639A39B8A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{71513020-B588-4A66-8122-E1639A39B8A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{71513020-B588-4A66-8122-E1639A39B8A8}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{71513020-B588-4A66-8122-E1639A39B8A8}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{71513020-B588-4A66-8122-E1639A39B8A8}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{71513020-B588-4A66-8122-E1639A39B8A8}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{71513020-B588-4A66-8122-E1639A39B8A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{71513020-B588-4A66-8122-E1639A39B8A8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{71513020-B588-4A66-8122-E1639A39B8A8}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{71513020-B588-4A66-8122-E1639A39B8A8}.Release|x64.Build.0 = Release|Any CPU
|
||||
{71513020-B588-4A66-8122-E1639A39B8A8}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{71513020-B588-4A66-8122-E1639A39B8A8}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -111,4 +111,4 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,14 +93,14 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
{
|
||||
internal class BZip2Compressor
|
||||
{
|
||||
private int blockSize100k; // 0...9
|
||||
private readonly int blockSize100k; // 0...9
|
||||
private int currentByte = -1;
|
||||
private int runLength = 0;
|
||||
private int last; // index into the block of the last char processed
|
||||
private int outBlockFillThreshold;
|
||||
private CompressionState cstate;
|
||||
private readonly CRC32 crc = new CRC32(true);
|
||||
BitWriter bw;
|
||||
private readonly int outBlockFillThreshold;
|
||||
private readonly CompressionState cstate;
|
||||
private readonly CRC32 crc = new(true);
|
||||
readonly BitWriter bw;
|
||||
int runs;
|
||||
|
||||
/*
|
||||
@@ -132,9 +132,9 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
* Possibly because the number of elems to sort is usually small, typically
|
||||
* <= 20.
|
||||
*/
|
||||
private static readonly int[] increments = { 1, 4, 13, 40, 121, 364, 1093, 3280,
|
||||
private static readonly int[] increments = [ 1, 4, 13, 40, 121, 364, 1093, 3280,
|
||||
9841, 29524, 88573, 265720, 797161,
|
||||
2391484 };
|
||||
2391484 ];
|
||||
|
||||
/// <summary>
|
||||
/// BZip2Compressor writes its compressed data out via a BitWriter. This
|
||||
@@ -1175,9 +1175,13 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
while (ll_i != tmp)
|
||||
{
|
||||
j++;
|
||||
#if NETCOREAPP || NETSTANDARD2_1_OR_GREATER
|
||||
(yy[j], tmp) = (tmp, yy[j]);
|
||||
#else
|
||||
byte tmp2 = tmp;
|
||||
tmp = yy[j];
|
||||
yy[j] = tmp2;
|
||||
#endif
|
||||
}
|
||||
yy[0] = tmp;
|
||||
|
||||
@@ -1690,9 +1694,13 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
while (ll_i != tmp)
|
||||
{
|
||||
j++;
|
||||
#if NETCOREAPP || NETSTANDARD2_1_OR_GREATER
|
||||
(pos[j], tmp) = (tmp, pos[j]);
|
||||
#else
|
||||
byte tmp2 = tmp;
|
||||
tmp = pos[j];
|
||||
pos[j] = tmp2;
|
||||
#endif
|
||||
}
|
||||
|
||||
pos[0] = tmp;
|
||||
@@ -1939,4 +1947,4 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
public class BZip2InputStream : System.IO.Stream
|
||||
{
|
||||
bool _disposed;
|
||||
bool _leaveOpen;
|
||||
readonly bool _leaveOpen;
|
||||
Int64 totalBytesRead;
|
||||
private int last;
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
private bool blockRandomised;
|
||||
private int bsBuff;
|
||||
private int bsLive;
|
||||
private readonly CRC32 crc = new CRC32(true);
|
||||
private readonly CRC32 crc = new(true);
|
||||
private int nInUse;
|
||||
private Stream input;
|
||||
private int currentChar = -1;
|
||||
@@ -491,8 +491,7 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
this.blockRandomised = (GetBits(1) == 1);
|
||||
|
||||
// Lazily allocate data
|
||||
if (this.data == null)
|
||||
this.data = new DecompressionState(this.blockSize100k);
|
||||
this.data ??= new DecompressionState(this.blockSize100k);
|
||||
|
||||
// currBlockNo++;
|
||||
getAndMoveToFrontDecode();
|
||||
@@ -1383,4 +1382,4 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,14 +92,14 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
public class BZip2OutputStream : System.IO.Stream
|
||||
{
|
||||
int totalBytesWrittenIn;
|
||||
bool leaveOpen;
|
||||
readonly bool leaveOpen;
|
||||
BZip2Compressor compressor;
|
||||
uint combinedCRC;
|
||||
Stream output;
|
||||
BitWriter bw;
|
||||
int blockSize100k; // 0...9
|
||||
readonly int blockSize100k; // 0...9
|
||||
|
||||
private TraceBits desiredTrace = TraceBits.Crc | TraceBits.Write;
|
||||
private readonly TraceBits desiredTrace = TraceBits.Crc | TraceBits.Write;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new <c>BZip2OutputStream</c>, that sends its
|
||||
|
||||
@@ -79,7 +79,6 @@
|
||||
// by multiple distinct threads, for different blocks of data.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace SabreTools.IO.Compression.BZip2
|
||||
@@ -88,7 +87,7 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
{
|
||||
uint accumulator;
|
||||
int nAccumulatedBits;
|
||||
Stream output;
|
||||
readonly Stream output;
|
||||
int totalBytesWrittenOut;
|
||||
|
||||
public BitWriter(Stream s)
|
||||
@@ -243,4 +242,4 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ using System;
|
||||
using Interop = System.Runtime.InteropServices;
|
||||
|
||||
#nullable disable
|
||||
#pragma warning disable CS0618
|
||||
namespace SabreTools.IO.Compression.BZip2
|
||||
{
|
||||
/// <summary>
|
||||
@@ -101,13 +100,13 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
|
||||
_TotalBytesRead = 0;
|
||||
int count = input.Read(buffer, 0, readSize);
|
||||
if (output != null) output.Write(buffer, 0, count);
|
||||
output?.Write(buffer, 0, count);
|
||||
_TotalBytesRead += count;
|
||||
while (count > 0)
|
||||
{
|
||||
SlurpBlock(buffer, 0, count);
|
||||
count = input.Read(buffer, 0, readSize);
|
||||
if (output != null) output.Write(buffer, 0, count);
|
||||
output?.Write(buffer, 0, count);
|
||||
_TotalBytesRead += count;
|
||||
}
|
||||
|
||||
@@ -279,7 +278,7 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
crc32Table[i] = dwCrc;
|
||||
}
|
||||
i++;
|
||||
} while (i!=0);
|
||||
} while (i != 0);
|
||||
}
|
||||
|
||||
#if VERBOSE
|
||||
@@ -303,10 +302,10 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
private uint gf2_matrix_times(uint[] matrix, uint vec)
|
||||
{
|
||||
uint sum = 0;
|
||||
int i=0;
|
||||
int i = 0;
|
||||
while (vec != 0)
|
||||
{
|
||||
if ((vec & 0x01)== 0x01)
|
||||
if ((vec & 0x01) == 0x01)
|
||||
sum ^= matrix[i];
|
||||
vec >>= 1;
|
||||
i++;
|
||||
@@ -341,8 +340,8 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
if (length == 0)
|
||||
return;
|
||||
|
||||
uint crc1= ~_register;
|
||||
uint crc2= (uint) crc;
|
||||
uint crc1 = ~_register;
|
||||
uint crc2 = (uint)crc;
|
||||
|
||||
// put operator for one zero bit in odd
|
||||
odd[0] = this.dwPolynomial; // the CRC-32 polynomial
|
||||
@@ -359,15 +358,16 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
// put operator for four zero bits in odd
|
||||
gf2_matrix_square(odd, even);
|
||||
|
||||
uint len2 = (uint) length;
|
||||
uint len2 = (uint)length;
|
||||
|
||||
// apply len2 zeros to crc1 (first square will put the operator for one
|
||||
// zero byte, eight zero bits, in even)
|
||||
do {
|
||||
do
|
||||
{
|
||||
// apply zeros operator for this bit of len2
|
||||
gf2_matrix_square(even, odd);
|
||||
|
||||
if ((len2 & 1)== 1)
|
||||
if ((len2 & 1) == 1)
|
||||
crc1 = gf2_matrix_times(even, crc1);
|
||||
len2 >>= 1;
|
||||
|
||||
@@ -376,7 +376,7 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
|
||||
// another iteration of the loop with odd and even swapped
|
||||
gf2_matrix_square(odd, even);
|
||||
if ((len2 & 1)==1)
|
||||
if ((len2 & 1) == 1)
|
||||
crc1 = gf2_matrix_times(odd, crc1);
|
||||
len2 >>= 1;
|
||||
|
||||
@@ -385,7 +385,7 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
|
||||
crc1 ^= crc2;
|
||||
|
||||
_register= ~crc1;
|
||||
_register = ~crc1;
|
||||
|
||||
//return (int) crc1;
|
||||
return;
|
||||
@@ -417,7 +417,7 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public CRC32(bool reverseBits) :
|
||||
this( unchecked((int)0xEDB88320), reverseBits)
|
||||
this(unchecked((int)0xEDB88320), reverseBits)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -450,7 +450,7 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
public CRC32(int polynomial, bool reverseBits)
|
||||
{
|
||||
this.reverseBits = reverseBits;
|
||||
this.dwPolynomial = (uint) polynomial;
|
||||
this.dwPolynomial = (uint)polynomial;
|
||||
this.GenerateLookupTable();
|
||||
}
|
||||
|
||||
@@ -469,9 +469,9 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
}
|
||||
|
||||
// private member vars
|
||||
private UInt32 dwPolynomial;
|
||||
private readonly UInt32 dwPolynomial;
|
||||
private Int64 _TotalBytesRead;
|
||||
private bool reverseBits;
|
||||
private readonly bool reverseBits;
|
||||
private UInt32[] crc32Table;
|
||||
private const int BUFFER_SIZE = 8192;
|
||||
private UInt32 _register = 0xFFFFFFFFU;
|
||||
@@ -502,8 +502,8 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
private static readonly Int64 UnsetLengthLimit = -99;
|
||||
|
||||
internal System.IO.Stream _innerStream;
|
||||
private CRC32 _Crc32;
|
||||
private Int64 _lengthLimit = -99;
|
||||
private readonly CRC32 _Crc32;
|
||||
private readonly Int64 _lengthLimit = -99;
|
||||
private bool _leaveOpen;
|
||||
|
||||
/// <summary>
|
||||
@@ -812,4 +812,4 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
{
|
||||
internal static class Rand
|
||||
{
|
||||
private static int[] RNUMS =
|
||||
{
|
||||
private static readonly int[] RNUMS =
|
||||
[
|
||||
619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
|
||||
985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
|
||||
733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
|
||||
@@ -82,7 +82,7 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
|
||||
645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
|
||||
936, 638
|
||||
};
|
||||
];
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -96,4 +96,4 @@ namespace SabreTools.IO.Compression.BZip2
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace SabreTools.IO.Compression.Blast
|
||||
/// that library. (Note: PKWare overused the "implode" verb, and the format
|
||||
/// used by their library implode() function is completely different and
|
||||
/// incompatible with the implode compression method supported by PKZIP.)
|
||||
///
|
||||
///
|
||||
/// The binary mode for stdio functions should be used to assure that the
|
||||
/// compressed data is not corrupted when read or written. For example:
|
||||
/// fopen(..., "rb") and fopen(..., "wb").
|
||||
@@ -168,29 +168,29 @@ namespace SabreTools.IO.Compression.Blast
|
||||
/// First byte is 0 if literals are uncoded or 1 if they are coded. Second
|
||||
/// byte is 4, 5, or 6 for the number of extra bits in the distance code.
|
||||
/// This is the base-2 logarithm of the dictionary size minus six.
|
||||
///
|
||||
///
|
||||
/// Compressed data is a combination of literals and length/distance pairs
|
||||
/// terminated by an end code. Literals are either Huffman coded or
|
||||
/// uncoded bytes. A length/distance pair is a coded length followed by a
|
||||
/// coded distance to represent a string that occurs earlier in the
|
||||
/// uncompressed data that occurs again at the current location.
|
||||
///
|
||||
///
|
||||
/// A bit preceding a literal or length/distance pair indicates which comes
|
||||
/// next, 0 for literals, 1 for length/distance.
|
||||
///
|
||||
///
|
||||
/// If literals are uncoded, then the next eight bits are the literal, in the
|
||||
/// normal bit order in the stream, i.e. no bit-reversal is needed. Similarly,
|
||||
/// no bit reversal is needed for either the length extra bits or the distance
|
||||
/// extra bits.
|
||||
///
|
||||
///
|
||||
/// Literal bytes are simply written to the output. A length/distance pair is
|
||||
/// an instruction to copy previously uncompressed bytes to the output. The
|
||||
/// copy is from distance bytes back in the output stream, copying for length
|
||||
/// bytes.
|
||||
///
|
||||
///
|
||||
/// Distances pointing before the beginning of the output data are not
|
||||
/// permitted.
|
||||
///
|
||||
///
|
||||
/// Overlapped copies, where the length is greater than the distance, are
|
||||
/// allowed and common. For example, a distance of one and a length of 518
|
||||
/// simply copies the last byte 518 times. A distance of four and a length of
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace SabreTools.IO.Compression.Blast
|
||||
/// bits are pulled from the compressed data one at a time and used to
|
||||
/// build the code value reversed from what is in the stream in order to
|
||||
/// permit simple integer comparisons for decoding.
|
||||
///
|
||||
///
|
||||
/// The first code for the shortest length is all ones. Subsequent codes of
|
||||
/// the same length are simply integer decrements of the previous code. When
|
||||
/// moving up a length, a one bit is appended to the code. For a complete
|
||||
|
||||
@@ -106,10 +106,6 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
// NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
|
||||
private static readonly int NMAX = 5552;
|
||||
|
||||
|
||||
#pragma warning disable 3001
|
||||
#pragma warning disable 3002
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the Adler32 checksum.
|
||||
/// </summary>
|
||||
@@ -172,9 +168,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
}
|
||||
return (uint)((s2 << 16) | s1);
|
||||
}
|
||||
#pragma warning restore 3001
|
||||
#pragma warning restore 3002
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,4 +75,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
FinishStarted, // finish started, need only more output at next deflate
|
||||
FinishDone // finish done, accept no more input or output
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ using System;
|
||||
using Interop = System.Runtime.InteropServices;
|
||||
|
||||
#nullable disable
|
||||
#pragma warning disable CS0618
|
||||
namespace SabreTools.IO.Compression.Deflate
|
||||
{
|
||||
/// <summary>
|
||||
@@ -101,13 +100,13 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
|
||||
_TotalBytesRead = 0;
|
||||
int count = input.Read(buffer, 0, readSize);
|
||||
if (output != null) output.Write(buffer, 0, count);
|
||||
output?.Write(buffer, 0, count);
|
||||
_TotalBytesRead += count;
|
||||
while (count > 0)
|
||||
{
|
||||
SlurpBlock(buffer, 0, count);
|
||||
count = input.Read(buffer, 0, readSize);
|
||||
if (output != null) output.Write(buffer, 0, count);
|
||||
output?.Write(buffer, 0, count);
|
||||
_TotalBytesRead += count;
|
||||
}
|
||||
|
||||
@@ -469,9 +468,9 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
}
|
||||
|
||||
// private member vars
|
||||
private UInt32 dwPolynomial;
|
||||
private readonly UInt32 dwPolynomial;
|
||||
private Int64 _TotalBytesRead;
|
||||
private bool reverseBits;
|
||||
private readonly bool reverseBits;
|
||||
private UInt32[] crc32Table;
|
||||
private const int BUFFER_SIZE = 8192;
|
||||
private UInt32 _register = 0xFFFFFFFFU;
|
||||
@@ -502,8 +501,8 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
private static readonly Int64 UnsetLengthLimit = -99;
|
||||
|
||||
internal System.IO.Stream _innerStream;
|
||||
private CRC32 _Crc32;
|
||||
private Int64 _lengthLimit = -99;
|
||||
private readonly CRC32 _Crc32;
|
||||
private readonly Int64 _lengthLimit = -99;
|
||||
private bool _leaveOpen;
|
||||
|
||||
/// <summary>
|
||||
@@ -812,4 +811,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,4 +165,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
Level9 = 9,
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,4 +103,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
Decompress = 1,
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,4 +116,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
HuffmanOnly = 2,
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
|
||||
static Config()
|
||||
{
|
||||
Table = new Config[] {
|
||||
Table = [
|
||||
new Config(0, 0, 0, 0, DeflateFlavor.Store),
|
||||
new Config(4, 4, 8, 4, DeflateFlavor.Fast),
|
||||
new Config(4, 5, 16, 8, DeflateFlavor.Fast),
|
||||
@@ -128,7 +128,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
new Config(8, 32, 128, 256, DeflateFlavor.Slow),
|
||||
new Config(32, 128, 258, 1024, DeflateFlavor.Slow),
|
||||
new Config(32, 258, 258, 4096, DeflateFlavor.Slow),
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
private static readonly Config[] Table;
|
||||
@@ -137,8 +137,8 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
|
||||
private CompressFunc DeflateFunction;
|
||||
|
||||
private static readonly System.String[] _ErrorMessage = new System.String[]
|
||||
{
|
||||
private static readonly System.String[] _ErrorMessage =
|
||||
[
|
||||
"need dictionary",
|
||||
"stream end",
|
||||
"",
|
||||
@@ -149,7 +149,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
"buffer error",
|
||||
"incompatible version",
|
||||
""
|
||||
};
|
||||
];
|
||||
|
||||
// preset dictionary flag in zlib header
|
||||
private static readonly int PRESET_DICT = 0x20;
|
||||
@@ -256,9 +256,9 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
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
|
||||
internal Tree treeBitLengths = new Tree(); // desc for bit length tree
|
||||
internal Tree treeLiterals = new(); // desc for literal tree
|
||||
internal Tree treeDistances = new(); // desc for distance tree
|
||||
internal Tree treeBitLengths = new(); // desc for bit length tree
|
||||
|
||||
// number of codes at each bit length for an optimal tree
|
||||
internal short[] bl_count = new short[InternalConstants.MAX_BITS + 1];
|
||||
@@ -1868,4 +1868,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -653,13 +653,11 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// <returns>The string in compressed form</returns>
|
||||
public static byte[] CompressString(String s)
|
||||
{
|
||||
using (var ms = new System.IO.MemoryStream())
|
||||
{
|
||||
System.IO.Stream compressor =
|
||||
new DeflateStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression);
|
||||
ZlibBaseStream.CompressString(s, compressor);
|
||||
return ms.ToArray();
|
||||
}
|
||||
using var ms = new System.IO.MemoryStream();
|
||||
System.IO.Stream compressor =
|
||||
new DeflateStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression);
|
||||
ZlibBaseStream.CompressString(s, compressor);
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -683,14 +681,12 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// <returns>The data in compressed form</returns>
|
||||
public static byte[] CompressBuffer(byte[] b)
|
||||
{
|
||||
using (var ms = new System.IO.MemoryStream())
|
||||
{
|
||||
System.IO.Stream compressor =
|
||||
new DeflateStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression);
|
||||
using var ms = new System.IO.MemoryStream();
|
||||
System.IO.Stream compressor =
|
||||
new DeflateStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression);
|
||||
|
||||
ZlibBaseStream.CompressBuffer(b, compressor);
|
||||
return ms.ToArray();
|
||||
}
|
||||
ZlibBaseStream.CompressBuffer(b, compressor);
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -710,13 +706,11 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// <returns>The uncompressed string</returns>
|
||||
public static String UncompressString(byte[] compressed)
|
||||
{
|
||||
using (var input = new System.IO.MemoryStream(compressed))
|
||||
{
|
||||
System.IO.Stream decompressor =
|
||||
new DeflateStream(input, CompressionMode.Decompress);
|
||||
using var input = new System.IO.MemoryStream(compressed);
|
||||
System.IO.Stream decompressor =
|
||||
new DeflateStream(input, CompressionMode.Decompress);
|
||||
|
||||
return ZlibBaseStream.UncompressString(compressed, decompressor);
|
||||
}
|
||||
return ZlibBaseStream.UncompressString(compressed, decompressor);
|
||||
}
|
||||
|
||||
|
||||
@@ -736,13 +730,11 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// <returns>The data in uncompressed form</returns>
|
||||
public static byte[] UncompressBuffer(byte[] compressed)
|
||||
{
|
||||
using (var input = new System.IO.MemoryStream(compressed))
|
||||
{
|
||||
System.IO.Stream decompressor =
|
||||
new DeflateStream(input, CompressionMode.Decompress);
|
||||
using var input = new System.IO.MemoryStream(compressed);
|
||||
System.IO.Stream decompressor =
|
||||
new DeflateStream(input, CompressionMode.Decompress);
|
||||
|
||||
return ZlibBaseStream.UncompressBuffer(compressed, decompressor);
|
||||
}
|
||||
return ZlibBaseStream.UncompressBuffer(compressed, decompressor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,4 +31,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// </summary>
|
||||
FAIL,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,4 +130,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
Finish,
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -547,7 +547,8 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
virtual public FlushType FlushMode
|
||||
{
|
||||
get { return (this._baseStream._flushMode); }
|
||||
set {
|
||||
set
|
||||
{
|
||||
if (_disposed) throw new ObjectDisposedException("GZipStream");
|
||||
this._baseStream._flushMode = value;
|
||||
}
|
||||
@@ -852,7 +853,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
#endregion
|
||||
|
||||
|
||||
internal static readonly System.DateTime _unixEpoch = new System.DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
internal static readonly System.DateTime _unixEpoch = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
#if SILVERLIGHT || NETCF
|
||||
internal static readonly System.Text.Encoding iso8859dash1 = new Ionic.Encoding.Iso8859Dash1Encoding();
|
||||
#else
|
||||
@@ -944,13 +945,11 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// <returns>The string in compressed form</returns>
|
||||
public static byte[] CompressString(String s)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
System.IO.Stream compressor =
|
||||
new GZipStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression);
|
||||
ZlibBaseStream.CompressString(s, compressor);
|
||||
return ms.ToArray();
|
||||
}
|
||||
using var ms = new MemoryStream();
|
||||
System.IO.Stream compressor =
|
||||
new GZipStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression);
|
||||
ZlibBaseStream.CompressString(s, compressor);
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -972,14 +971,12 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// <returns>The data in compressed form</returns>
|
||||
public static byte[] CompressBuffer(byte[] b)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
System.IO.Stream compressor =
|
||||
new GZipStream( ms, CompressionMode.Compress, CompressionLevel.BestCompression );
|
||||
using var ms = new MemoryStream();
|
||||
System.IO.Stream compressor =
|
||||
new GZipStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression);
|
||||
|
||||
ZlibBaseStream.CompressBuffer(b, compressor);
|
||||
return ms.ToArray();
|
||||
}
|
||||
ZlibBaseStream.CompressBuffer(b, compressor);
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -997,11 +994,9 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// <returns>The uncompressed string</returns>
|
||||
public static String UncompressString(byte[] compressed)
|
||||
{
|
||||
using (var input = new MemoryStream(compressed))
|
||||
{
|
||||
Stream decompressor = new GZipStream(input, CompressionMode.Decompress);
|
||||
return ZlibBaseStream.UncompressString(compressed, decompressor);
|
||||
}
|
||||
using var input = new MemoryStream(compressed);
|
||||
Stream decompressor = new GZipStream(input, CompressionMode.Decompress);
|
||||
return ZlibBaseStream.UncompressString(compressed, decompressor);
|
||||
}
|
||||
|
||||
|
||||
@@ -1019,13 +1014,11 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// <returns>The data in uncompressed form</returns>
|
||||
public static byte[] UncompressBuffer(byte[] compressed)
|
||||
{
|
||||
using (var input = new System.IO.MemoryStream(compressed))
|
||||
{
|
||||
System.IO.Stream decompressor =
|
||||
new GZipStream( input, CompressionMode.Decompress );
|
||||
using var input = new System.IO.MemoryStream(compressed);
|
||||
System.IO.Stream decompressor =
|
||||
new GZipStream(input, CompressionMode.Decompress);
|
||||
|
||||
return ZlibBaseStream.UncompressBuffer(compressed, decompressor);
|
||||
}
|
||||
return ZlibBaseStream.UncompressBuffer(compressed, decompressor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
// Inftree.cs
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation.
|
||||
// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This code module is part of DotNetZip, a zipfile class library.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// This code is licensed under the Microsoft Public License.
|
||||
// This code is licensed under the Microsoft Public License.
|
||||
// See the file License.txt for the license details.
|
||||
// More info on: http://dotnetzip.codeplex.com
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// last saved (in emacs):
|
||||
// last saved (in emacs):
|
||||
// Time-stamp: <2009-October-28 12:43:54>
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// This module defines classes used in decompression. This code is derived
|
||||
// from the jzlib implementation of zlib. In keeping with the license for jzlib,
|
||||
// from the jzlib implementation of zlib. In keeping with the license for jzlib,
|
||||
// the copyright to that code is below.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
|
||||
//
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
//
|
||||
// 3. The names of the authors may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
@@ -50,7 +50,7 @@
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
//
|
||||
// This program is based on zlib-1.1.3; credit to authors
|
||||
@@ -83,31 +83,31 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
internal const int fixed_bd = 5;
|
||||
|
||||
//UPGRADE_NOTE: Final was removed from the declaration of 'fixed_tl'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
|
||||
internal static readonly int[] fixed_tl = new int[]{96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 192, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 160, 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 224, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 144, 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 208, 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 176, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 240, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 200, 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 168, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 232, 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 152, 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 216, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 184, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 248, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 196, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 164, 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 228, 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 148, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 212, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 180, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 244, 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 204, 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 172, 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 236, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 156, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 220, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 188, 0, 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 252, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 194, 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 162, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 226, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 146, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 210, 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 178, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 242, 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 202, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 170, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 234, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 154, 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 218, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 186,
|
||||
internal static readonly int[] fixed_tl = [96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 192, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 160, 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 224, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 144, 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 208, 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 176, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 240, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 200, 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 168, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 232, 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 152, 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 216, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 184, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 248, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 196, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 164, 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 228, 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 148, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 212, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 180, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 244, 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 204, 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 172, 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 236, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 156, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 220, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 188, 0, 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 252, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 194, 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 162, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 226, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 146, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 210, 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 178, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 242, 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 202, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 170, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 234, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 154, 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 218, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 186,
|
||||
0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 250, 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 198, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 166, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 230, 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 150, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 214, 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 182, 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 246, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 206, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 174, 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 238, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 158, 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 222, 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 190, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 254, 96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 193, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 161, 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 225, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 145, 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 209, 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 177, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 241, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 201, 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 169, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 233, 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 153, 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 217, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 185, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 249, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 197, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 165, 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 229, 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 149, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 213, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 181, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 245, 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 205, 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 173, 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 237, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 157, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 221, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 189, 0, 8,
|
||||
14, 0, 8, 142, 0, 8, 78, 0, 9, 253, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 195, 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 163, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 227, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 147, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 211, 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 179, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 243, 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 203, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 171, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 235, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 155, 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 219, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 187, 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 251, 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 199, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 167, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 231, 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 151, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 215, 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 183, 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 247, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 207, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 175, 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 239, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 159, 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 223, 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 191, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 255};
|
||||
14, 0, 8, 142, 0, 8, 78, 0, 9, 253, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 195, 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 163, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 227, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 147, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 211, 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 179, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 243, 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 203, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 171, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 235, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 155, 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 219, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 187, 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 251, 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 199, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 167, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 231, 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 151, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 215, 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 183, 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 247, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 207, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 175, 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 239, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 159, 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 223, 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 191, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 255];
|
||||
//UPGRADE_NOTE: Final was removed from the declaration of 'fixed_td'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
|
||||
internal static readonly int[] fixed_td = new int[] { 80, 5, 1, 87, 5, 257, 83, 5, 17, 91, 5, 4097, 81, 5, 5, 89, 5, 1025, 85, 5, 65, 93, 5, 16385, 80, 5, 3, 88, 5, 513, 84, 5, 33, 92, 5, 8193, 82, 5, 9, 90, 5, 2049, 86, 5, 129, 192, 5, 24577, 80, 5, 2, 87, 5, 385, 83, 5, 25, 91, 5, 6145, 81, 5, 7, 89, 5, 1537, 85, 5, 97, 93, 5, 24577, 80, 5, 4, 88, 5, 769, 84, 5, 49, 92, 5, 12289, 82, 5, 13, 90, 5, 3073, 86, 5, 193, 192, 5, 24577 };
|
||||
internal static readonly int[] fixed_td = [80, 5, 1, 87, 5, 257, 83, 5, 17, 91, 5, 4097, 81, 5, 5, 89, 5, 1025, 85, 5, 65, 93, 5, 16385, 80, 5, 3, 88, 5, 513, 84, 5, 33, 92, 5, 8193, 82, 5, 9, 90, 5, 2049, 86, 5, 129, 192, 5, 24577, 80, 5, 2, 87, 5, 385, 83, 5, 25, 91, 5, 6145, 81, 5, 7, 89, 5, 1537, 85, 5, 97, 93, 5, 24577, 80, 5, 4, 88, 5, 769, 84, 5, 49, 92, 5, 12289, 82, 5, 13, 90, 5, 3073, 86, 5, 193, 192, 5, 24577];
|
||||
|
||||
// Tables for deflate from PKZIP's appnote.txt.
|
||||
//UPGRADE_NOTE: Final was removed from the declaration of 'cplens'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
|
||||
internal static readonly int[] cplens = new int[] { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 };
|
||||
internal static readonly int[] cplens = [3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0];
|
||||
|
||||
// see note #13 above about 258
|
||||
//UPGRADE_NOTE: Final was removed from the declaration of 'cplext'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
|
||||
internal static readonly int[] cplext = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 };
|
||||
internal static readonly int[] cplext = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112];
|
||||
|
||||
//UPGRADE_NOTE: Final was removed from the declaration of 'cpdist'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
|
||||
internal static readonly int[] cpdist = new int[] { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 };
|
||||
internal static readonly int[] cpdist = [1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577];
|
||||
|
||||
//UPGRADE_NOTE: Final was removed from the declaration of 'cpdext'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
|
||||
internal static readonly int[] cpdext = new int[] { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 };
|
||||
internal static readonly int[] cpdext = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13];
|
||||
|
||||
// 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[] 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
|
||||
@@ -432,4 +432,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,8 +71,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
private const int MANY = 1440;
|
||||
|
||||
// Table for deflate from PKZIP's appnote.txt.
|
||||
internal static readonly int[] border = new int[]
|
||||
{ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
|
||||
internal static readonly int[] border = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
|
||||
|
||||
private enum InflateBlockMode
|
||||
{
|
||||
@@ -98,7 +97,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
internal int[] bb = new int[1]; // bit length tree depth
|
||||
internal int[] tb = new int[1]; // bit length decoding tree
|
||||
|
||||
internal InflateCodes codes = new InflateCodes(); // if CODES, current state
|
||||
internal InflateCodes codes = new(); // if CODES, current state
|
||||
|
||||
internal int last; // true if this block is the last block
|
||||
|
||||
@@ -115,7 +114,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
internal System.Object checkfn; // check function
|
||||
internal uint check; // check on output
|
||||
|
||||
internal InfTree inftree = new InfTree();
|
||||
internal InfTree inftree = new();
|
||||
|
||||
internal InflateBlocks(ZlibCodec codec, System.Object checkfn, int w)
|
||||
{
|
||||
@@ -545,8 +544,8 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
|
||||
tb[0] = -1;
|
||||
{
|
||||
int[] bl = new int[] { 9 }; // must be <= 9 for lookahead assumptions
|
||||
int[] bd = new int[] { 6 }; // must be <= 9 for lookahead assumptions
|
||||
int[] bl = [9]; // must be <= 9 for lookahead assumptions
|
||||
int[] bd = [6]; // must be <= 9 for lookahead assumptions
|
||||
int[] tl = new int[1];
|
||||
int[] td = new int[1];
|
||||
|
||||
@@ -734,4 +733,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -720,4 +720,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
return ZlibConstants.Z_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,8 +135,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
|
||||
internal int End()
|
||||
{
|
||||
if (blocks != null)
|
||||
blocks.Free();
|
||||
blocks?.Free();
|
||||
blocks = null;
|
||||
return ZlibConstants.Z_OK;
|
||||
}
|
||||
@@ -392,7 +391,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
}
|
||||
|
||||
|
||||
private static readonly byte[] mark = new byte[] { 0, 0, 0xff, 0xff };
|
||||
private static readonly byte[] mark = [0, 0, 0xff, 0xff];
|
||||
|
||||
internal int Sync()
|
||||
{
|
||||
@@ -462,4 +461,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
return blocks.SyncPoint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,4 +467,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,25 +90,25 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
{
|
||||
internal static class InternalConstants
|
||||
{
|
||||
internal static readonly int MAX_BITS = 15;
|
||||
internal static readonly int BL_CODES = 19;
|
||||
internal static readonly int D_CODES = 30;
|
||||
internal static readonly int LITERALS = 256;
|
||||
internal static readonly int MAX_BITS = 15;
|
||||
internal static readonly int BL_CODES = 19;
|
||||
internal static readonly int D_CODES = 30;
|
||||
internal static readonly int LITERALS = 256;
|
||||
internal static readonly int LENGTH_CODES = 29;
|
||||
internal static readonly int L_CODES = (LITERALS + 1 + LENGTH_CODES);
|
||||
internal static readonly int L_CODES = (LITERALS + 1 + LENGTH_CODES);
|
||||
|
||||
// Bit length codes must not exceed MAX_BL_BITS bits
|
||||
internal static readonly int MAX_BL_BITS = 7;
|
||||
internal static readonly int MAX_BL_BITS = 7;
|
||||
|
||||
// repeat previous bit length 3-6 times (2 bits of repeat count)
|
||||
internal static readonly int REP_3_6 = 16;
|
||||
internal static readonly int REP_3_6 = 16;
|
||||
|
||||
// repeat a zero length 3-10 times (3 bits of repeat count)
|
||||
internal static readonly int REPZ_3_10 = 17;
|
||||
internal static readonly int REPZ_3_10 = 17;
|
||||
|
||||
// repeat a zero length 11-138 times (7 bits of repeat count)
|
||||
internal static readonly int REPZ_11_138 = 18;
|
||||
internal static readonly int REPZ_11_138 = 18;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,10 +66,10 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
internal static class InternalInflateConstants
|
||||
{
|
||||
// And'ing with mask[n] masks the lower n bits
|
||||
internal static readonly int[] InflateMask = new int[] {
|
||||
internal static readonly int[] InflateMask = [
|
||||
0x00000000, 0x00000001, 0x00000003, 0x00000007,
|
||||
0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
|
||||
0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
|
||||
0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff };
|
||||
0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,4 +159,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
{
|
||||
internal sealed class StaticTree
|
||||
{
|
||||
internal static readonly short[] lengthAndLiteralsTreeCodes = new short[] {
|
||||
internal static readonly short[] lengthAndLiteralsTreeCodes = [
|
||||
12, 8, 140, 8, 76, 8, 204, 8, 44, 8, 172, 8, 108, 8, 236, 8,
|
||||
28, 8, 156, 8, 92, 8, 220, 8, 60, 8, 188, 8, 124, 8, 252, 8,
|
||||
2, 8, 130, 8, 66, 8, 194, 8, 34, 8, 162, 8, 98, 8, 226, 8,
|
||||
@@ -127,13 +127,13 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
8, 7, 72, 7, 40, 7, 104, 7, 24, 7, 88, 7, 56, 7, 120, 7,
|
||||
4, 7, 68, 7, 36, 7, 100, 7, 20, 7, 84, 7, 52, 7, 116, 7,
|
||||
3, 8, 131, 8, 67, 8, 195, 8, 35, 8, 163, 8, 99, 8, 227, 8
|
||||
};
|
||||
];
|
||||
|
||||
internal static readonly short[] distTreeCodes = new short[] {
|
||||
internal static readonly short[] distTreeCodes = [
|
||||
0, 5, 16, 5, 8, 5, 24, 5, 4, 5, 20, 5, 12, 5, 28, 5,
|
||||
2, 5, 18, 5, 10, 5, 26, 5, 6, 5, 22, 5, 14, 5, 30, 5,
|
||||
1, 5, 17, 5, 9, 5, 25, 5, 5, 5, 21, 5, 13, 5, 29, 5,
|
||||
3, 5, 19, 5, 11, 5, 27, 5, 7, 5, 23, 5 };
|
||||
3, 5, 19, 5, 11, 5, 27, 5, 7, 5, 23, 5 ];
|
||||
|
||||
internal static readonly StaticTree Literals;
|
||||
internal static readonly StaticTree Distances;
|
||||
@@ -161,4 +161,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
// Tree.cs
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation.
|
||||
// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This code module is part of DotNetZip, a zipfile class library.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// This code is licensed under the Microsoft Public License.
|
||||
// This code is licensed under the Microsoft Public License.
|
||||
// See the file License.txt for the license details.
|
||||
// More info on: http://dotnetzip.codeplex.com
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// last saved (in emacs):
|
||||
// last saved (in emacs):
|
||||
// Time-stamp: <2009-October-28 13:29:50>
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
@@ -25,22 +25,22 @@
|
||||
// code is below.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
|
||||
//
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
//
|
||||
// 3. The names of the authors may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
@@ -51,7 +51,7 @@
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
//
|
||||
// This program is based on zlib-1.1.3; credit to authors
|
||||
@@ -66,74 +66,74 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
sealed class Tree
|
||||
{
|
||||
private static readonly int HEAP_SIZE = (2 * InternalConstants.L_CODES + 1);
|
||||
|
||||
|
||||
// extra bits for each length code
|
||||
internal static readonly int[] ExtraLengthBits = new int[]
|
||||
{
|
||||
internal static readonly int[] ExtraLengthBits =
|
||||
[
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0
|
||||
};
|
||||
|
||||
];
|
||||
|
||||
// extra bits for each distance code
|
||||
internal static readonly int[] ExtraDistanceBits = new int[]
|
||||
{
|
||||
internal static readonly int[] ExtraDistanceBits =
|
||||
[
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
|
||||
7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13
|
||||
};
|
||||
|
||||
];
|
||||
|
||||
// extra bits for each bit length code
|
||||
internal static readonly int[] extra_blbits = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7};
|
||||
|
||||
internal static readonly sbyte[] bl_order = new sbyte[]{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
||||
|
||||
|
||||
internal static readonly int[] extra_blbits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7];
|
||||
|
||||
internal static readonly sbyte[] bl_order = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
|
||||
|
||||
|
||||
// The lengths of the bit length codes are sent in order of decreasing
|
||||
// probability, to avoid transmitting the lengths for unused bit
|
||||
// length codes.
|
||||
|
||||
|
||||
internal const int Buf_size = 8 * 2;
|
||||
|
||||
|
||||
// see definition of array dist_code below
|
||||
//internal const int DIST_CODE_LEN = 512;
|
||||
|
||||
private static readonly sbyte[] _dist_code = new sbyte[]
|
||||
{
|
||||
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
|
||||
|
||||
private static readonly sbyte[] _dist_code =
|
||||
[
|
||||
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
0, 0, 16, 17, 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21,
|
||||
22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
|
||||
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
0, 0, 16, 17, 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21,
|
||||
22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
|
||||
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
|
||||
};
|
||||
|
||||
internal static readonly sbyte[] LengthCode = new sbyte[]
|
||||
{
|
||||
];
|
||||
|
||||
internal static readonly sbyte[] LengthCode =
|
||||
[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11,
|
||||
12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15,
|
||||
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17,
|
||||
@@ -150,27 +150,27 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
|
||||
};
|
||||
|
||||
];
|
||||
|
||||
internal static readonly int[] LengthBase = new int[]
|
||||
{
|
||||
|
||||
internal static readonly int[] LengthBase =
|
||||
[
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28,
|
||||
32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 0
|
||||
};
|
||||
|
||||
];
|
||||
|
||||
internal static readonly int[] DistanceBase = new int[]
|
||||
{
|
||||
|
||||
internal static readonly int[] DistanceBase =
|
||||
[
|
||||
0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192,
|
||||
256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
|
||||
};
|
||||
];
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Map from a distance to a distance code.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <remarks>
|
||||
/// No side effects. _dist_code[256] and _dist_code[257] are never used.
|
||||
/// </remarks>
|
||||
internal static int DistanceCode(int dist)
|
||||
@@ -183,7 +183,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
internal short[] dyn_tree; // the dynamic tree
|
||||
internal int max_code; // largest code with non zero frequency
|
||||
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.
|
||||
// IN assertion: the fields freq and dad are set, heap[heap_max] and
|
||||
@@ -192,7 +192,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
// array bl_count contains the frequencies for each bit length.
|
||||
// The length opt_len is updated; static_len is also updated if stree is
|
||||
// not null.
|
||||
internal void gen_bitlen(DeflateManager s)
|
||||
internal void gen_bitlen(DeflateManager s)
|
||||
{
|
||||
short[] tree = dyn_tree;
|
||||
short[] stree = staticTree.treeCodes;
|
||||
@@ -205,14 +205,14 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
int xbits; // extra bits
|
||||
short f; // frequency
|
||||
int overflow = 0; // number of elements with bit length too large
|
||||
|
||||
|
||||
for (bits = 0; bits <= InternalConstants.MAX_BITS; bits++)
|
||||
s.bl_count[bits] = 0;
|
||||
|
||||
|
||||
// In a first pass, compute the optimal bit lengths (which may
|
||||
// overflow in the case of the bit length tree).
|
||||
tree[s.heap[s.heap_max] * 2 + 1] = 0; // root of the heap
|
||||
|
||||
|
||||
for (h = s.heap_max + 1; h < HEAP_SIZE; h++)
|
||||
{
|
||||
n = s.heap[h];
|
||||
@@ -221,12 +221,12 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
{
|
||||
bits = max_length; overflow++;
|
||||
}
|
||||
tree[n * 2 + 1] = (short) bits;
|
||||
tree[n * 2 + 1] = (short)bits;
|
||||
// We overwrite tree[n*2+1] which is no longer needed
|
||||
|
||||
|
||||
if (n > max_code)
|
||||
continue; // not a leaf node
|
||||
|
||||
|
||||
s.bl_count[bits]++;
|
||||
xbits = 0;
|
||||
if (n >= base_Renamed)
|
||||
@@ -237,24 +237,24 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
s.static_len += f * (stree[n * 2 + 1] + xbits);
|
||||
}
|
||||
if (overflow == 0)
|
||||
return ;
|
||||
|
||||
return;
|
||||
|
||||
// This happens for example on obj2 and pic of the Calgary corpus
|
||||
// Find the first bit length which could increase:
|
||||
do
|
||||
do
|
||||
{
|
||||
bits = max_length - 1;
|
||||
while (s.bl_count[bits] == 0)
|
||||
bits--;
|
||||
s.bl_count[bits]--; // move one leaf down the tree
|
||||
s.bl_count[bits + 1] = (short) (s.bl_count[bits + 1] + 2); // move one overflow item as its brother
|
||||
s.bl_count[bits + 1] = (short)(s.bl_count[bits + 1] + 2); // move one overflow item as its brother
|
||||
s.bl_count[max_length]--;
|
||||
// The brother of the overflow item also moves one step up,
|
||||
// but this does not affect bl_count[max_length]
|
||||
overflow -= 2;
|
||||
}
|
||||
while (overflow > 0);
|
||||
|
||||
|
||||
for (bits = max_length; bits != 0; bits--)
|
||||
{
|
||||
n = s.bl_count[bits];
|
||||
@@ -265,35 +265,35 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
continue;
|
||||
if (tree[m * 2 + 1] != bits)
|
||||
{
|
||||
s.opt_len = (int) (s.opt_len + ((long) bits - (long) tree[m * 2 + 1]) * (long) tree[m * 2]);
|
||||
tree[m * 2 + 1] = (short) bits;
|
||||
s.opt_len = (int)(s.opt_len + ((long)bits - (long)tree[m * 2 + 1]) * (long)tree[m * 2]);
|
||||
tree[m * 2 + 1] = (short)bits;
|
||||
}
|
||||
n--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Construct one Huffman tree and assigns the code bit strings and lengths.
|
||||
// Update the total bit length for the current block.
|
||||
// IN assertion: the field freq is set for all tree elements.
|
||||
// OUT assertions: the fields len and code are set to the optimal bit length
|
||||
// and corresponding code. The length opt_len is updated; static_len is
|
||||
// also updated if stree is not null. The field max_code is set.
|
||||
internal void build_tree(DeflateManager s)
|
||||
internal void build_tree(DeflateManager s)
|
||||
{
|
||||
short[] tree = dyn_tree;
|
||||
short[] tree = dyn_tree;
|
||||
short[] stree = staticTree.treeCodes;
|
||||
int elems = staticTree.elems;
|
||||
int elems = staticTree.elems;
|
||||
int n, m; // iterate over heap elements
|
||||
int max_code = -1; // largest code with non zero frequency
|
||||
int max_code = -1; // largest code with non zero frequency
|
||||
int node; // new node being created
|
||||
|
||||
|
||||
// Construct the initial heap, with least frequent element in
|
||||
// heap[1]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
|
||||
// heap[0] is not used.
|
||||
s.heap_len = 0;
|
||||
s.heap_max = HEAP_SIZE;
|
||||
|
||||
|
||||
for (n = 0; n < elems; n++)
|
||||
{
|
||||
if (tree[n * 2] != 0)
|
||||
@@ -306,14 +306,14 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
tree[n * 2 + 1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// The pkzip format requires that at least one distance code exists,
|
||||
// and that at least one bit should be sent even if there is only one
|
||||
// possible code. So to avoid special checks later on we force at least
|
||||
// two codes of non zero frequency.
|
||||
while (s.heap_len < 2)
|
||||
{
|
||||
node = s.heap[++s.heap_len] = (max_code < 2?++max_code:0);
|
||||
node = s.heap[++s.heap_len] = (max_code < 2 ? ++max_code : 0);
|
||||
tree[node * 2] = 1;
|
||||
s.depth[node] = 0;
|
||||
s.opt_len--;
|
||||
@@ -322,93 +322,94 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
// node is 0 or 1 so it does not have extra bits
|
||||
}
|
||||
this.max_code = max_code;
|
||||
|
||||
|
||||
// The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
|
||||
// establish sub-heaps of increasing lengths:
|
||||
|
||||
|
||||
for (n = s.heap_len / 2; n >= 1; n--)
|
||||
s.pqdownheap(tree, n);
|
||||
|
||||
|
||||
// Construct the Huffman tree by repeatedly combining the least two
|
||||
// frequent nodes.
|
||||
|
||||
|
||||
node = elems; // next internal node of the tree
|
||||
do
|
||||
do
|
||||
{
|
||||
// n = node of least frequency
|
||||
n = s.heap[1];
|
||||
s.heap[1] = s.heap[s.heap_len--];
|
||||
s.pqdownheap(tree, 1);
|
||||
m = s.heap[1]; // m = node of next least frequency
|
||||
|
||||
|
||||
s.heap[--s.heap_max] = n; // keep the nodes sorted by frequency
|
||||
s.heap[--s.heap_max] = m;
|
||||
|
||||
|
||||
// Create a new node father of n and m
|
||||
tree[node * 2] = unchecked((short) (tree[n * 2] + tree[m * 2]));
|
||||
s.depth[node] = (sbyte) (System.Math.Max((byte) s.depth[n], (byte) s.depth[m]) + 1);
|
||||
tree[n * 2 + 1] = tree[m * 2 + 1] = (short) node;
|
||||
|
||||
tree[node * 2] = unchecked((short)(tree[n * 2] + tree[m * 2]));
|
||||
s.depth[node] = (sbyte)(System.Math.Max((byte)s.depth[n], (byte)s.depth[m]) + 1);
|
||||
tree[n * 2 + 1] = tree[m * 2 + 1] = (short)node;
|
||||
|
||||
// and insert the new node in the heap
|
||||
s.heap[1] = node++;
|
||||
s.pqdownheap(tree, 1);
|
||||
}
|
||||
while (s.heap_len >= 2);
|
||||
|
||||
|
||||
s.heap[--s.heap_max] = s.heap[1];
|
||||
|
||||
|
||||
// At this point, the fields freq and dad are set. We can now
|
||||
// generate the bit lengths.
|
||||
|
||||
|
||||
gen_bitlen(s);
|
||||
|
||||
|
||||
// The field len is now set, we can generate the bit codes
|
||||
gen_codes(tree, max_code, s.bl_count);
|
||||
}
|
||||
|
||||
|
||||
// Generate the codes for a given tree and bit counts (which need not be
|
||||
// optimal).
|
||||
// IN assertion: the array bl_count contains the bit length statistics for
|
||||
// the given tree and the field len is set for all tree elements.
|
||||
// OUT assertion: the field code is set for all tree elements of non
|
||||
// zero code length.
|
||||
internal static void gen_codes(short[] tree, int max_code, short[] bl_count)
|
||||
internal static void gen_codes(short[] tree, int max_code, short[] bl_count)
|
||||
{
|
||||
short[] next_code = new short[InternalConstants.MAX_BITS + 1]; // next code value for each bit length
|
||||
short code = 0; // running code value
|
||||
int bits; // bit index
|
||||
int n; // code index
|
||||
|
||||
|
||||
// The distribution counts are first used to generate the code values
|
||||
// without bit reversal.
|
||||
for (bits = 1; bits <= InternalConstants.MAX_BITS; bits++)
|
||||
unchecked {
|
||||
next_code[bits] = code = (short) ((code + bl_count[bits - 1]) << 1);
|
||||
unchecked
|
||||
{
|
||||
next_code[bits] = code = (short)((code + bl_count[bits - 1]) << 1);
|
||||
}
|
||||
|
||||
|
||||
// Check that the bit counts in bl_count are consistent. The last code
|
||||
// must be all ones.
|
||||
//Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
|
||||
// "inconsistent bit counts");
|
||||
//Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
|
||||
|
||||
|
||||
for (n = 0; n <= max_code; n++)
|
||||
{
|
||||
int len = tree[n * 2 + 1];
|
||||
if (len == 0)
|
||||
continue;
|
||||
// Now reverse the bits
|
||||
tree[n * 2] = unchecked((short) (bi_reverse(next_code[len]++, len)));
|
||||
tree[n * 2] = unchecked((short)(bi_reverse(next_code[len]++, len)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Reverse the first len bits of a code, using straightforward code (a faster
|
||||
// method would use a table)
|
||||
// IN assertion: 1 <= len <= 15
|
||||
internal static int bi_reverse(int code, int len)
|
||||
{
|
||||
int res = 0;
|
||||
do
|
||||
do
|
||||
{
|
||||
res |= code & 1;
|
||||
code >>= 1; //SharedUtils.URShift(code, 1);
|
||||
@@ -418,4 +419,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
return res >> 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ using System;
|
||||
using System.IO;
|
||||
|
||||
#nullable disable
|
||||
#pragma warning disable CA2022
|
||||
namespace SabreTools.IO.Compression.Deflate
|
||||
{
|
||||
internal class ZlibBaseStream : System.IO.Stream
|
||||
@@ -49,7 +48,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
protected internal CompressionStrategy Strategy = CompressionStrategy.Default;
|
||||
|
||||
// workitem 7159
|
||||
CRC32 crc;
|
||||
readonly CRC32 crc;
|
||||
protected internal string _GzipFileName;
|
||||
protected internal string _GzipComment;
|
||||
protected internal DateTime _GzipMtime;
|
||||
@@ -115,8 +114,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_workingBuffer == null)
|
||||
_workingBuffer = new byte[_bufferSize];
|
||||
_workingBuffer ??= new byte[_bufferSize];
|
||||
return _workingBuffer;
|
||||
}
|
||||
}
|
||||
@@ -127,8 +125,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
{
|
||||
// workitem 7159
|
||||
// calculate the CRC on the unccompressed data (before writing)
|
||||
if (crc != null)
|
||||
crc.SlurpBlock(buffer, offset, count);
|
||||
crc?.SlurpBlock(buffer, offset, count);
|
||||
|
||||
if (_streamMode == StreamMode.Undefined)
|
||||
_streamMode = StreamMode.Writer;
|
||||
@@ -142,7 +139,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
z.InputBuffer = buffer;
|
||||
_z.NextIn = offset;
|
||||
_z.AvailableBytesIn = count;
|
||||
bool done = false;
|
||||
bool done;
|
||||
do
|
||||
{
|
||||
_z.OutputBuffer = workingBuffer;
|
||||
@@ -175,7 +172,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
|
||||
if (_streamMode == StreamMode.Writer)
|
||||
{
|
||||
bool done = false;
|
||||
bool done;
|
||||
do
|
||||
{
|
||||
_z.OutputBuffer = workingBuffer;
|
||||
@@ -363,7 +360,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
list.Add(_buf1[0]);
|
||||
}
|
||||
} while (!done);
|
||||
byte[] a = list.ToArray();
|
||||
byte[] a = [.. list];
|
||||
return GZipStream.iso8859dash1.GetString(a, 0, a.Length);
|
||||
}
|
||||
|
||||
@@ -406,7 +403,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
if ((header[3] & 0x10) == 0x010)
|
||||
_GzipComment = ReadZeroTerminatedString();
|
||||
if ((header[3] & 0x02) == 0x02)
|
||||
Read(_buf1, 0, 1); // CRC16, ignore
|
||||
_ = Read(_buf1, 0, 1); // CRC16, ignore
|
||||
|
||||
return totalBytesRead;
|
||||
}
|
||||
@@ -448,7 +445,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
if (offset < buffer.GetLowerBound(0)) throw new ArgumentOutOfRangeException("offset");
|
||||
if ((offset + count) > buffer.GetLength(0)) throw new ArgumentOutOfRangeException("count");
|
||||
|
||||
int rc = 0;
|
||||
int rc;
|
||||
|
||||
// set up the output of the deflate/inflate codec:
|
||||
_z.OutputBuffer = buffer;
|
||||
@@ -519,8 +516,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
rc = (count - _z.AvailableBytesOut);
|
||||
|
||||
// calculate CRC after reading
|
||||
if (crc != null)
|
||||
crc.SlurpBlock(buffer, offset, rc);
|
||||
crc?.SlurpBlock(buffer, offset, rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -584,40 +580,36 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
// workitem 8460
|
||||
byte[] working = new byte[1024];
|
||||
var encoding = System.Text.Encoding.UTF8;
|
||||
using (var output = new MemoryStream())
|
||||
using var output = new MemoryStream();
|
||||
using (decompressor)
|
||||
{
|
||||
using (decompressor)
|
||||
int n;
|
||||
while ((n = decompressor.Read(working, 0, working.Length)) != 0)
|
||||
{
|
||||
int n;
|
||||
while ((n = decompressor.Read(working, 0, working.Length)) != 0)
|
||||
{
|
||||
output.Write(working, 0, n);
|
||||
}
|
||||
output.Write(working, 0, n);
|
||||
}
|
||||
|
||||
// reset to allow read from start
|
||||
output.Seek(0, SeekOrigin.Begin);
|
||||
var sr = new StreamReader(output, encoding);
|
||||
return sr.ReadToEnd();
|
||||
}
|
||||
|
||||
// reset to allow read from start
|
||||
output.Seek(0, SeekOrigin.Begin);
|
||||
var sr = new StreamReader(output, encoding);
|
||||
return sr.ReadToEnd();
|
||||
}
|
||||
|
||||
public static byte[] UncompressBuffer(byte[] compressed, Stream decompressor)
|
||||
{
|
||||
// workitem 8460
|
||||
byte[] working = new byte[1024];
|
||||
using (var output = new MemoryStream())
|
||||
using var output = new MemoryStream();
|
||||
using (decompressor)
|
||||
{
|
||||
using (decompressor)
|
||||
int n;
|
||||
while ((n = decompressor.Read(working, 0, working.Length)) != 0)
|
||||
{
|
||||
int n;
|
||||
while ((n = decompressor.Read(working, 0, working.Length)) != 0)
|
||||
{
|
||||
output.Write(working, 0, n);
|
||||
}
|
||||
output.Write(working, 0, n);
|
||||
}
|
||||
return output.ToArray();
|
||||
}
|
||||
return output.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
// ZlibCodec.cs
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation.
|
||||
// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This code module is part of DotNetZip, a zipfile class library.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// This code is licensed under the Microsoft Public License.
|
||||
// This code is licensed under the Microsoft Public License.
|
||||
// See the file License.txt for the license details.
|
||||
// More info on: http://dotnetzip.codeplex.com
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// last saved (in emacs):
|
||||
// last saved (in emacs):
|
||||
// Time-stamp: <2009-November-03 15:40:51>
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
@@ -28,22 +28,22 @@
|
||||
// is included below.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
|
||||
//
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
//
|
||||
// 3. The names of the authors may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
@@ -54,7 +54,7 @@
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
//
|
||||
// This program is based on zlib-1.1.3; credit to authors
|
||||
@@ -68,7 +68,6 @@ using System;
|
||||
using Interop=System.Runtime.InteropServices;
|
||||
|
||||
#nullable disable
|
||||
#pragma warning disable CS0618
|
||||
namespace SabreTools.IO.Compression.Deflate
|
||||
{
|
||||
/// <summary>
|
||||
@@ -83,7 +82,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// </remarks>
|
||||
[Interop.GuidAttribute("ebc25cf6-9120-4283-b972-0e5520d0000D")]
|
||||
[Interop.ComVisible(true)]
|
||||
#if !NETCF
|
||||
#if !NETCF
|
||||
[Interop.ClassInterface(Interop.ClassInterfaceType.AutoDispatch)]
|
||||
#endif
|
||||
sealed public class ZlibCodec
|
||||
@@ -94,15 +93,15 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
public byte[] InputBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// An index into the InputBuffer array, indicating where to start reading.
|
||||
/// An index into the InputBuffer array, indicating where to start reading.
|
||||
/// </summary>
|
||||
public int NextIn;
|
||||
|
||||
/// <summary>
|
||||
/// The number of bytes available in the InputBuffer, starting at NextIn.
|
||||
/// The number of bytes available in the InputBuffer, starting at NextIn.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Generally you should set this to InputBuffer.Length before the first Inflate() or Deflate() call.
|
||||
/// Generally you should set this to InputBuffer.Length before the first Inflate() or Deflate() call.
|
||||
/// The class will update this number as calls to Inflate/Deflate are made.
|
||||
/// </remarks>
|
||||
public int AvailableBytesIn;
|
||||
@@ -118,15 +117,15 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
public byte[] OutputBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// An index into the OutputBuffer array, indicating where to start writing.
|
||||
/// An index into the OutputBuffer array, indicating where to start writing.
|
||||
/// </summary>
|
||||
public int NextOut;
|
||||
|
||||
/// <summary>
|
||||
/// The number of bytes available in the OutputBuffer, starting at NextOut.
|
||||
/// The number of bytes available in the OutputBuffer, starting at NextOut.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Generally you should set this to OutputBuffer.Length before the first Inflate() or Deflate() call.
|
||||
/// Generally you should set this to OutputBuffer.Length before the first Inflate() or Deflate() call.
|
||||
/// The class will update this number as calls to Inflate/Deflate are made.
|
||||
/// </remarks>
|
||||
public int AvailableBytesOut;
|
||||
@@ -152,13 +151,13 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
public CompressionLevel CompressLevel = CompressionLevel.Default;
|
||||
|
||||
/// <summary>
|
||||
/// The number of Window Bits to use.
|
||||
/// The number of Window Bits to use.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This gauges the size of the sliding window, and hence the
|
||||
/// compression effectiveness as well as memory consumption. It's best to just leave this
|
||||
/// This gauges the size of the sliding window, and hence the
|
||||
/// compression effectiveness as well as memory consumption. It's best to just leave this
|
||||
/// setting alone if you don't know what it is. The maximum value is 15 bits, which implies
|
||||
/// a 32k window.
|
||||
/// a 32k window.
|
||||
/// </remarks>
|
||||
public int WindowBits = ZlibConstants.WindowBitsDefault;
|
||||
|
||||
@@ -188,9 +187,9 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// Create a ZlibCodec.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If you use this default constructor, you will later have to explicitly call
|
||||
/// InitializeInflate() or InitializeDeflate() before using the ZlibCodec to compress
|
||||
/// or decompress.
|
||||
/// If you use this default constructor, you will later have to explicitly call
|
||||
/// InitializeInflate() or InitializeDeflate() before using the ZlibCodec to compress
|
||||
/// or decompress.
|
||||
/// </remarks>
|
||||
public ZlibCodec() { }
|
||||
|
||||
@@ -216,10 +215,10 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the inflation state.
|
||||
/// Initialize the inflation state.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// It is not necessary to call this before using the ZlibCodec to inflate data;
|
||||
/// It is not necessary to call this before using the ZlibCodec to inflate data;
|
||||
/// It is implicitly called when you call the constructor.
|
||||
/// </remarks>
|
||||
/// <returns>Z_OK if everything goes well.</returns>
|
||||
@@ -252,20 +251,20 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the ZlibCodec for inflation, with the specified number of window bits.
|
||||
/// Initialize the ZlibCodec for inflation, with the specified number of window bits.
|
||||
/// </summary>
|
||||
/// <param name="windowBits">The number of window bits to use. If you need to ask what that is,
|
||||
/// <param name="windowBits">The number of window bits to use. If you need to ask what that is,
|
||||
/// then you shouldn't be calling this initializer.</param>
|
||||
/// <returns>Z_OK if all goes well.</returns>
|
||||
public int InitializeInflate(int windowBits)
|
||||
{
|
||||
this.WindowBits = windowBits;
|
||||
this.WindowBits = windowBits;
|
||||
return InitializeInflate(windowBits, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the inflation state with an explicit flag to govern the handling of
|
||||
/// RFC1950 header bytes.
|
||||
/// RFC1950 header bytes.
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
@@ -277,9 +276,9 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// false.
|
||||
/// </remarks>
|
||||
///
|
||||
/// <param name="expectRfc1950Header">whether to expect an RFC1950 header byte pair when reading
|
||||
/// <param name="expectRfc1950Header">whether to expect an RFC1950 header byte pair when reading
|
||||
/// the stream of data to be inflated.</param>
|
||||
/// <param name="windowBits">The number of window bits to use. If you need to ask what that is,
|
||||
/// <param name="windowBits">The number of window bits to use. If you need to ask what that is,
|
||||
/// then you shouldn't be calling this initializer.</param>
|
||||
/// <returns>Z_OK if everything goes well.</returns>
|
||||
public int InitializeInflate(int windowBits, bool expectRfc1950Header)
|
||||
@@ -294,7 +293,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// Inflate the data in the InputBuffer, placing the result in the OutputBuffer.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// You must have set InputBuffer and OutputBuffer, NextIn and NextOut, and AvailableBytesIn and
|
||||
/// You must have set InputBuffer and OutputBuffer, NextIn and NextOut, and AvailableBytesIn and
|
||||
/// AvailableBytesOut before calling this method.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
@@ -304,48 +303,48 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// int bufferSize = 1024;
|
||||
/// byte[] buffer = new byte[bufferSize];
|
||||
/// ZlibCodec decompressor = new ZlibCodec();
|
||||
///
|
||||
///
|
||||
/// Console.WriteLine("\n============================================");
|
||||
/// Console.WriteLine("Size of Buffer to Inflate: {0} bytes.", CompressedBytes.Length);
|
||||
/// MemoryStream ms = new MemoryStream(DecompressedBytes);
|
||||
///
|
||||
///
|
||||
/// int rc = decompressor.InitializeInflate();
|
||||
///
|
||||
///
|
||||
/// decompressor.InputBuffer = CompressedBytes;
|
||||
/// decompressor.NextIn = 0;
|
||||
/// decompressor.AvailableBytesIn = CompressedBytes.Length;
|
||||
///
|
||||
///
|
||||
/// decompressor.OutputBuffer = buffer;
|
||||
///
|
||||
/// // pass 1: inflate
|
||||
///
|
||||
/// // pass 1: inflate
|
||||
/// do
|
||||
/// {
|
||||
/// decompressor.NextOut = 0;
|
||||
/// decompressor.AvailableBytesOut = buffer.Length;
|
||||
/// rc = decompressor.Inflate(FlushType.None);
|
||||
///
|
||||
///
|
||||
/// if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END)
|
||||
/// throw new Exception("inflating: " + decompressor.Message);
|
||||
///
|
||||
///
|
||||
/// ms.Write(decompressor.OutputBuffer, 0, buffer.Length - decompressor.AvailableBytesOut);
|
||||
/// }
|
||||
/// while (decompressor.AvailableBytesIn > 0 || decompressor.AvailableBytesOut == 0);
|
||||
///
|
||||
///
|
||||
/// // pass 2: finish and flush
|
||||
/// do
|
||||
/// {
|
||||
/// decompressor.NextOut = 0;
|
||||
/// decompressor.AvailableBytesOut = buffer.Length;
|
||||
/// rc = decompressor.Inflate(FlushType.Finish);
|
||||
///
|
||||
///
|
||||
/// if (rc != ZlibConstants.Z_STREAM_END && rc != ZlibConstants.Z_OK)
|
||||
/// throw new Exception("inflating: " + decompressor.Message);
|
||||
///
|
||||
///
|
||||
/// if (buffer.Length - decompressor.AvailableBytesOut > 0)
|
||||
/// ms.Write(buffer, 0, buffer.Length - decompressor.AvailableBytesOut);
|
||||
/// }
|
||||
/// while (decompressor.AvailableBytesIn > 0 || decompressor.AvailableBytesOut == 0);
|
||||
///
|
||||
///
|
||||
/// decompressor.EndInflate();
|
||||
/// }
|
||||
///
|
||||
@@ -362,10 +361,10 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Ends an inflation session.
|
||||
/// Ends an inflation session.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Call this after successively calling Inflate(). This will cause all buffers to be flushed.
|
||||
/// Call this after successively calling Inflate(). This will cause all buffers to be flushed.
|
||||
/// After calling this you cannot call Inflate() without a intervening call to one of the
|
||||
/// InitializeInflate() overloads.
|
||||
/// </remarks>
|
||||
@@ -401,32 +400,32 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// int bufferSize = 40000;
|
||||
/// byte[] CompressedBytes = new byte[bufferSize];
|
||||
/// byte[] DecompressedBytes = new byte[bufferSize];
|
||||
///
|
||||
///
|
||||
/// ZlibCodec compressor = new ZlibCodec();
|
||||
///
|
||||
///
|
||||
/// compressor.InitializeDeflate(CompressionLevel.Default);
|
||||
///
|
||||
///
|
||||
/// compressor.InputBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(TextToCompress);
|
||||
/// compressor.NextIn = 0;
|
||||
/// compressor.AvailableBytesIn = compressor.InputBuffer.Length;
|
||||
///
|
||||
///
|
||||
/// compressor.OutputBuffer = CompressedBytes;
|
||||
/// compressor.NextOut = 0;
|
||||
/// compressor.AvailableBytesOut = CompressedBytes.Length;
|
||||
///
|
||||
///
|
||||
/// while (compressor.TotalBytesIn != TextToCompress.Length && compressor.TotalBytesOut < bufferSize)
|
||||
/// {
|
||||
/// compressor.Deflate(FlushType.None);
|
||||
/// }
|
||||
///
|
||||
///
|
||||
/// while (true)
|
||||
/// {
|
||||
/// int rc= compressor.Deflate(FlushType.Finish);
|
||||
/// if (rc == ZlibConstants.Z_STREAM_END) break;
|
||||
/// }
|
||||
///
|
||||
///
|
||||
/// compressor.EndDeflate();
|
||||
///
|
||||
///
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// <returns>Z_OK if all goes well. You generally don't need to check the return code.</returns>
|
||||
@@ -452,7 +451,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel,
|
||||
/// Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel,
|
||||
/// and the explicit flag governing whether to emit an RFC1950 header byte pair.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
@@ -460,7 +459,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// If you want to generate a zlib stream, you should specify true for
|
||||
/// wantRfc1950Header. In this case, the library will emit a ZLIB
|
||||
/// header, as defined in <see href="http://www.ietf.org/rfc/rfc1950.txt">RFC
|
||||
/// 1950</see>, in the compressed stream.
|
||||
/// 1950</see>, in the compressed stream.
|
||||
/// </remarks>
|
||||
/// <param name="level">The compression level for the codec.</param>
|
||||
/// <param name="wantRfc1950Header">whether to emit an initial RFC1950 byte pair in the compressed stream.</param>
|
||||
@@ -473,8 +472,8 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel,
|
||||
/// and the specified number of window bits.
|
||||
/// Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel,
|
||||
/// and the specified number of window bits.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The codec will use the specified number of window bits and the specified CompressionLevel.
|
||||
@@ -509,8 +508,10 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
private int _InternalInitializeDeflate(bool wantRfc1950Header)
|
||||
{
|
||||
if (istate != null) throw new ZlibException("You may not call InitializeDeflate() after calling InitializeInflate().");
|
||||
dstate = new DeflateManager();
|
||||
dstate.WantRfc1950HeaderBytes = wantRfc1950Header;
|
||||
dstate = new DeflateManager
|
||||
{
|
||||
WantRfc1950HeaderBytes = wantRfc1950Header
|
||||
};
|
||||
|
||||
return dstate.Initialize(this, this.CompressLevel, this.WindowBits, this.Strategy);
|
||||
}
|
||||
@@ -528,59 +529,59 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// int bufferSize = 1024;
|
||||
/// byte[] buffer = new byte[bufferSize];
|
||||
/// ZlibCodec compressor = new ZlibCodec();
|
||||
///
|
||||
///
|
||||
/// Console.WriteLine("\n============================================");
|
||||
/// Console.WriteLine("Size of Buffer to Deflate: {0} bytes.", UncompressedBytes.Length);
|
||||
/// MemoryStream ms = new MemoryStream();
|
||||
///
|
||||
///
|
||||
/// int rc = compressor.InitializeDeflate(level);
|
||||
///
|
||||
///
|
||||
/// compressor.InputBuffer = UncompressedBytes;
|
||||
/// compressor.NextIn = 0;
|
||||
/// compressor.AvailableBytesIn = UncompressedBytes.Length;
|
||||
///
|
||||
///
|
||||
/// compressor.OutputBuffer = buffer;
|
||||
///
|
||||
/// // pass 1: deflate
|
||||
///
|
||||
/// // pass 1: deflate
|
||||
/// do
|
||||
/// {
|
||||
/// compressor.NextOut = 0;
|
||||
/// compressor.AvailableBytesOut = buffer.Length;
|
||||
/// rc = compressor.Deflate(FlushType.None);
|
||||
///
|
||||
///
|
||||
/// if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END)
|
||||
/// throw new Exception("deflating: " + compressor.Message);
|
||||
///
|
||||
///
|
||||
/// ms.Write(compressor.OutputBuffer, 0, buffer.Length - compressor.AvailableBytesOut);
|
||||
/// }
|
||||
/// while (compressor.AvailableBytesIn > 0 || compressor.AvailableBytesOut == 0);
|
||||
///
|
||||
///
|
||||
/// // pass 2: finish and flush
|
||||
/// do
|
||||
/// {
|
||||
/// compressor.NextOut = 0;
|
||||
/// compressor.AvailableBytesOut = buffer.Length;
|
||||
/// rc = compressor.Deflate(FlushType.Finish);
|
||||
///
|
||||
///
|
||||
/// if (rc != ZlibConstants.Z_STREAM_END && rc != ZlibConstants.Z_OK)
|
||||
/// throw new Exception("deflating: " + compressor.Message);
|
||||
///
|
||||
///
|
||||
/// if (buffer.Length - compressor.AvailableBytesOut > 0)
|
||||
/// ms.Write(buffer, 0, buffer.Length - compressor.AvailableBytesOut);
|
||||
/// }
|
||||
/// while (compressor.AvailableBytesIn > 0 || compressor.AvailableBytesOut == 0);
|
||||
///
|
||||
///
|
||||
/// compressor.EndDeflate();
|
||||
///
|
||||
///
|
||||
/// ms.Seek(0, SeekOrigin.Begin);
|
||||
/// CompressedBytes = new byte[compressor.TotalBytesOut];
|
||||
/// ms.Read(CompressedBytes, 0, CompressedBytes.Length);
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// <param name="flush">whether to flush all data as you deflate. Generally you will want to
|
||||
/// use Z_NO_FLUSH here, in a series of calls to Deflate(), and then call EndDeflate() to
|
||||
/// flush everything.
|
||||
/// <param name="flush">whether to flush all data as you deflate. Generally you will want to
|
||||
/// use Z_NO_FLUSH here, in a series of calls to Deflate(), and then call EndDeflate() to
|
||||
/// flush everything.
|
||||
/// </param>
|
||||
/// <returns>Z_OK if all goes well.</returns>
|
||||
public int Deflate(FlushType flush)
|
||||
@@ -717,4 +718,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
// ZlibConstants.cs
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation.
|
||||
// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This code module is part of DotNetZip, a zipfile class library.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// This code is licensed under the Microsoft Public License.
|
||||
// This code is licensed under the Microsoft Public License.
|
||||
// See the file License.txt for the license details.
|
||||
// More info on: http://dotnetzip.codeplex.com
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// last saved (in emacs):
|
||||
// last saved (in emacs):
|
||||
// Time-stamp: <2009-November-03 18:50:19>
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
@@ -25,22 +25,22 @@
|
||||
// copyright to that code is included here.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
|
||||
//
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
//
|
||||
// 3. The names of the authors may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
@@ -51,7 +51,7 @@
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
//
|
||||
// This program is based on zlib-1.1.3; credit to authors
|
||||
@@ -91,7 +91,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
public const int Z_STREAM_END = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The operation ended in need of a dictionary.
|
||||
/// The operation ended in need of a dictionary.
|
||||
/// </summary>
|
||||
public const int Z_NEED_DICT = 2;
|
||||
|
||||
|
||||
@@ -117,4 +117,4 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -545,7 +545,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// <returns>the number of bytes read</returns>
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (_disposed) throw new ObjectDisposedException("ZlibStream");
|
||||
if (_disposed) throw new ObjectDisposedException("ZlibStream");
|
||||
return _baseStream.Read(buffer, offset, count);
|
||||
}
|
||||
|
||||
@@ -607,7 +607,7 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// <param name="count">the number of bytes to write.</param>
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (_disposed) throw new ObjectDisposedException("ZlibStream");
|
||||
if (_disposed) throw new ObjectDisposedException("ZlibStream");
|
||||
_baseStream.Write(buffer, offset, count);
|
||||
}
|
||||
#endregion
|
||||
@@ -633,13 +633,11 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// <returns>The string in compressed form</returns>
|
||||
public static byte[] CompressString(String s)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
Stream compressor =
|
||||
new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression);
|
||||
ZlibBaseStream.CompressString(s, compressor);
|
||||
return ms.ToArray();
|
||||
}
|
||||
using var ms = new MemoryStream();
|
||||
Stream compressor =
|
||||
new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression);
|
||||
ZlibBaseStream.CompressString(s, compressor);
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -661,14 +659,12 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// <returns>The data in compressed form</returns>
|
||||
public static byte[] CompressBuffer(byte[] b)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
Stream compressor =
|
||||
new ZlibStream( ms, CompressionMode.Compress, CompressionLevel.BestCompression );
|
||||
using var ms = new MemoryStream();
|
||||
Stream compressor =
|
||||
new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression);
|
||||
|
||||
ZlibBaseStream.CompressBuffer(b, compressor);
|
||||
return ms.ToArray();
|
||||
}
|
||||
ZlibBaseStream.CompressBuffer(b, compressor);
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -686,13 +682,11 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// <returns>The uncompressed string</returns>
|
||||
public static String UncompressString(byte[] compressed)
|
||||
{
|
||||
using (var input = new MemoryStream(compressed))
|
||||
{
|
||||
Stream decompressor =
|
||||
new ZlibStream(input, CompressionMode.Decompress);
|
||||
using var input = new MemoryStream(compressed);
|
||||
Stream decompressor =
|
||||
new ZlibStream(input, CompressionMode.Decompress);
|
||||
|
||||
return ZlibBaseStream.UncompressString(compressed, decompressor);
|
||||
}
|
||||
return ZlibBaseStream.UncompressString(compressed, decompressor);
|
||||
}
|
||||
|
||||
|
||||
@@ -710,16 +704,14 @@ namespace SabreTools.IO.Compression.Deflate
|
||||
/// <returns>The data in uncompressed form</returns>
|
||||
public static byte[] UncompressBuffer(byte[] compressed)
|
||||
{
|
||||
using (var input = new MemoryStream(compressed))
|
||||
{
|
||||
Stream decompressor =
|
||||
new ZlibStream( input, CompressionMode.Decompress );
|
||||
using var input = new MemoryStream(compressed);
|
||||
Stream decompressor =
|
||||
new ZlibStream(input, CompressionMode.Decompress);
|
||||
|
||||
return ZlibBaseStream.UncompressBuffer(compressed, decompressor);
|
||||
}
|
||||
return ZlibBaseStream.UncompressBuffer(compressed, decompressor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,4 +55,4 @@ namespace SabreTools.IO.Compression.LZX
|
||||
/// <remarks>Variable</remarks>
|
||||
public byte[]? TokenSequence { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,4 @@ namespace SabreTools.IO.Compression.LZX
|
||||
/// </summary>
|
||||
public BlockData? BlockData { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,4 +5,4 @@ namespace SabreTools.IO.Compression.LZX
|
||||
{
|
||||
// No common fields between all block data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,4 +30,4 @@ namespace SabreTools.IO.Compression.LZX
|
||||
/// <remarks>8 bits</remarks>
|
||||
public byte BlocksizeLSB { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,4 @@ namespace SabreTools.IO.Compression.LZX
|
||||
/// </summary>
|
||||
public Block[]? Blocks { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,4 +43,4 @@ namespace SabreTools.IO.Compression.LZX
|
||||
/// </summary>
|
||||
public ushort? TranslationSizeLowWord { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,4 +35,4 @@ namespace SabreTools.IO.Compression.LZX
|
||||
|
||||
public const int LZX_LENTABLE_SAFETY = 64; /* we allow length table decoding overruns */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ namespace SabreTools.IO.Compression.LZX
|
||||
/// begins. Following the zero padding, new 32-bit values for R0, R1, and R2 are output in little-endian
|
||||
/// form, followed by the uncompressed data bytes themselves. Finally, if the uncompressed data length
|
||||
/// is odd, one extra byte of zero padding is encoded to realign the following bitstream.
|
||||
///
|
||||
///
|
||||
/// Then the bitstream of byte-swapped 16-bit integers resumes for the next Block Type field (if there
|
||||
/// are subsequent blocks).
|
||||
///
|
||||
///
|
||||
/// The decoded R0, R1, and R2 values are used as initial repeated offset values to decode the
|
||||
/// subsequent compressed block if present.
|
||||
/// </summary>
|
||||
@@ -51,4 +51,4 @@ namespace SabreTools.IO.Compression.LZX
|
||||
/// </summary>
|
||||
public byte AlignmentByte { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,4 +48,4 @@ namespace SabreTools.IO.Compression.LZX
|
||||
/// <remarks>Variable</remarks>
|
||||
public byte[]? TokenSequence { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace SabreTools.IO.Compression.MSZIP
|
||||
/// Each MSZIP block MUST consist of a 2-byte MSZIP signature and one or more RFC 1951 blocks. The
|
||||
/// 2-byte MSZIP signature MUST consist of the bytes 0x43 and 0x4B. The MSZIP signature MUST be
|
||||
/// the first 2 bytes in the MSZIP block. The MSZIP signature is shown in the following packet diagram.
|
||||
///
|
||||
///
|
||||
/// Each MSZIP block is the result of a single deflate compression operation, as defined in [RFC1951].
|
||||
/// The compressor that performs the compression operation MUST generate one or more RFC 1951
|
||||
/// blocks, as defined in [RFC1951]. The number, deflation mode, and type of RFC 1951 blocks in each
|
||||
@@ -12,7 +12,7 @@ namespace SabreTools.IO.Compression.MSZIP
|
||||
/// each MSZIP block MUST be marked as the "end" of the stream(1), as defined by [RFC1951]
|
||||
/// section 3.2.3. Decoding trees MUST be discarded after each RFC 1951 block, but the history buffer
|
||||
/// MUST be maintained.Each MSZIP block MUST represent no more than 32 KB of uncompressed data.
|
||||
///
|
||||
///
|
||||
/// The maximum compressed size of each MSZIP block is 32 KB + 12 bytes. This enables the MSZIP
|
||||
/// block to contain 32 KB of data split between two noncompressed RFC 1951 blocks, each of which
|
||||
/// has a value of BTYPE = 00.
|
||||
@@ -25,4 +25,4 @@ namespace SabreTools.IO.Compression.MSZIP
|
||||
/// </summary>
|
||||
public ushort Signature { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,4 +47,4 @@ namespace SabreTools.IO.Compression.Quantum
|
||||
20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using static SabreTools.IO.Compression.Quantum.Constants;
|
||||
|
||||
namespace SabreTools.IO.Compression.Quantum
|
||||
{
|
||||
/// <see href="www.russotto.net/quantumcomp.html"/>
|
||||
/// <see href="www.russotto.net/quantumcomp.html"/>
|
||||
public class Decompressor
|
||||
{
|
||||
/// <summary>
|
||||
@@ -362,9 +362,13 @@ namespace SabreTools.IO.Compression.Quantum
|
||||
{
|
||||
if (model.Symbols![i]!.CumulativeFrequency < model.Symbols![j]!.CumulativeFrequency)
|
||||
{
|
||||
#if NETCOREAPP || NETSTANDARD2_1_OR_GREATER
|
||||
(model.Symbols[j], model.Symbols[i]) = (model.Symbols[i], model.Symbols[j]);
|
||||
#else
|
||||
var temp = model.Symbols[i];
|
||||
model.Symbols[i] = model.Symbols[j];
|
||||
model.Symbols[j] = temp;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,4 +42,4 @@ namespace SabreTools.IO.Compression.Quantum
|
||||
/// </summary>
|
||||
SELECTOR_6_LENGTH = 7,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,4 @@ namespace SabreTools.IO.Compression.Quantum
|
||||
/// <remarks>The initial time_to_reorder value is 4</remarks>
|
||||
public int TimeToReorder { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,4 @@ namespace SabreTools.IO.Compression.Quantum
|
||||
/// </summary>
|
||||
public ushort CumulativeFrequency { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace SabreTools.IO.Compression.SZDD
|
||||
/// </summary>
|
||||
public static Decompressor CreateSZDD(Stream source)
|
||||
{
|
||||
// Create the decompressor
|
||||
// Create the decompressors
|
||||
var decompressor = new Decompressor(source);
|
||||
|
||||
// Set the format and return
|
||||
|
||||
@@ -215,4 +215,4 @@ namespace SabreTools.IO.Compression.zlib
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,26 +3,26 @@ using System.Threading;
|
||||
|
||||
namespace SabreTools.IO.Compression.zlib
|
||||
{
|
||||
public unsafe static class MemoryStats
|
||||
{
|
||||
private static int _allocations;
|
||||
|
||||
public static int Allocations
|
||||
{
|
||||
get
|
||||
{
|
||||
return _allocations;
|
||||
}
|
||||
}
|
||||
public unsafe static class MemoryStats
|
||||
{
|
||||
private static int _allocations;
|
||||
|
||||
internal static void Allocated()
|
||||
{
|
||||
Interlocked.Increment(ref _allocations);
|
||||
}
|
||||
public static int Allocations
|
||||
{
|
||||
get
|
||||
{
|
||||
return _allocations;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Freed()
|
||||
{
|
||||
Interlocked.Decrement(ref _allocations);
|
||||
}
|
||||
}
|
||||
}
|
||||
internal static void Allocated()
|
||||
{
|
||||
Interlocked.Increment(ref _allocations);
|
||||
}
|
||||
|
||||
internal static void Freed()
|
||||
{
|
||||
Interlocked.Decrement(ref _allocations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,86 +3,86 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace SabreTools.IO.Compression.zlib
|
||||
{
|
||||
public unsafe class UnsafeArray1D<T> where T : struct
|
||||
{
|
||||
private readonly T[] _data;
|
||||
private readonly GCHandle _pinHandle;
|
||||
public bool IsFreed { get; private set; }
|
||||
public unsafe class UnsafeArray1D<T> where T : struct
|
||||
{
|
||||
private readonly T[] _data;
|
||||
private readonly GCHandle _pinHandle;
|
||||
public bool IsFreed { get; private set; }
|
||||
|
||||
internal GCHandle PinHandle => _pinHandle;
|
||||
internal GCHandle PinHandle => _pinHandle;
|
||||
|
||||
public T this[int index]
|
||||
{
|
||||
get => _data[index];
|
||||
set
|
||||
{
|
||||
_data[index] = value;
|
||||
}
|
||||
}
|
||||
public T this[int index]
|
||||
{
|
||||
get => _data[index];
|
||||
set
|
||||
{
|
||||
_data[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public T this[uint index]
|
||||
{
|
||||
get => _data[index];
|
||||
set
|
||||
{
|
||||
_data[index] = value;
|
||||
}
|
||||
}
|
||||
public T this[uint index]
|
||||
{
|
||||
get => _data[index];
|
||||
set
|
||||
{
|
||||
_data[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public T[] Data => _data;
|
||||
public T[] Data => _data;
|
||||
|
||||
public UnsafeArray1D(int size)
|
||||
{
|
||||
if (size < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(size));
|
||||
}
|
||||
public UnsafeArray1D(int size)
|
||||
{
|
||||
if (size < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(size));
|
||||
}
|
||||
|
||||
_data = new T[size];
|
||||
_pinHandle = GCHandle.Alloc(_data, GCHandleType.Pinned);
|
||||
IsFreed = false;
|
||||
}
|
||||
_data = new T[size];
|
||||
_pinHandle = GCHandle.Alloc(_data, GCHandleType.Pinned);
|
||||
IsFreed = false;
|
||||
}
|
||||
|
||||
public UnsafeArray1D(T[] data, int sizeOf)
|
||||
{
|
||||
if (sizeOf <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(sizeOf));
|
||||
}
|
||||
public UnsafeArray1D(T[] data, int sizeOf)
|
||||
{
|
||||
if (sizeOf <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(sizeOf));
|
||||
}
|
||||
|
||||
_data = data ?? throw new ArgumentNullException(nameof(data));
|
||||
_pinHandle = GCHandle.Alloc(_data, GCHandleType.Pinned);
|
||||
IsFreed = false;
|
||||
}
|
||||
_data = data ?? throw new ArgumentNullException(nameof(data));
|
||||
_pinHandle = GCHandle.Alloc(_data, GCHandleType.Pinned);
|
||||
IsFreed = false;
|
||||
}
|
||||
|
||||
public void Free()
|
||||
{
|
||||
if (!IsFreed)
|
||||
{
|
||||
_pinHandle.Free();
|
||||
IsFreed = true;
|
||||
}
|
||||
}
|
||||
public void Free()
|
||||
{
|
||||
if (!IsFreed)
|
||||
{
|
||||
_pinHandle.Free();
|
||||
IsFreed = true;
|
||||
}
|
||||
}
|
||||
|
||||
~UnsafeArray1D()
|
||||
{
|
||||
if (!IsFreed)
|
||||
_pinHandle.Free();
|
||||
}
|
||||
~UnsafeArray1D()
|
||||
{
|
||||
if (!IsFreed)
|
||||
_pinHandle.Free();
|
||||
}
|
||||
|
||||
public void* ToPointer()
|
||||
{
|
||||
return _pinHandle.AddrOfPinnedObject().ToPointer();
|
||||
}
|
||||
public void* ToPointer()
|
||||
{
|
||||
return _pinHandle.AddrOfPinnedObject().ToPointer();
|
||||
}
|
||||
|
||||
public static implicit operator void*(UnsafeArray1D<T> array)
|
||||
{
|
||||
return array.ToPointer();
|
||||
}
|
||||
public static implicit operator void*(UnsafeArray1D<T> array)
|
||||
{
|
||||
return array.ToPointer();
|
||||
}
|
||||
|
||||
public static void* operator +(UnsafeArray1D<T> array, int delta)
|
||||
{
|
||||
return array.ToPointer();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void* operator +(UnsafeArray1D<T> array, int delta)
|
||||
{
|
||||
return array.ToPointer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,44 +2,44 @@
|
||||
|
||||
namespace SabreTools.IO.Compression.zlib
|
||||
{
|
||||
public unsafe class UnsafeArray2D<T> where T : struct
|
||||
{
|
||||
private readonly UnsafeArray1D<T>[] _data;
|
||||
private long[] _pinAddresses;
|
||||
private readonly GCHandle _pinAddressesHandle;
|
||||
public unsafe class UnsafeArray2D<T> where T : struct
|
||||
{
|
||||
private readonly UnsafeArray1D<T>[] _data;
|
||||
private long[] _pinAddresses;
|
||||
private readonly GCHandle _pinAddressesHandle;
|
||||
|
||||
public UnsafeArray1D<T> this[int index]
|
||||
{
|
||||
get => _data[index];
|
||||
set
|
||||
{
|
||||
_data[index] = value;
|
||||
}
|
||||
}
|
||||
public UnsafeArray1D<T> this[int index]
|
||||
{
|
||||
get => _data[index];
|
||||
set
|
||||
{
|
||||
_data[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public UnsafeArray2D(int size1, int size2)
|
||||
{
|
||||
_data = new UnsafeArray1D<T>[size1];
|
||||
_pinAddresses = new long[size1];
|
||||
for (var i = 0; i < size1; ++i)
|
||||
{
|
||||
_data[i] = new UnsafeArray1D<T>(size2);
|
||||
_pinAddresses[i] = _data[i].PinHandle.AddrOfPinnedObject().ToInt64();
|
||||
}
|
||||
public UnsafeArray2D(int size1, int size2)
|
||||
{
|
||||
_data = new UnsafeArray1D<T>[size1];
|
||||
_pinAddresses = new long[size1];
|
||||
for (var i = 0; i < size1; ++i)
|
||||
{
|
||||
_data[i] = new UnsafeArray1D<T>(size2);
|
||||
_pinAddresses[i] = _data[i].PinHandle.AddrOfPinnedObject().ToInt64();
|
||||
}
|
||||
|
||||
_pinAddressesHandle = GCHandle.Alloc(_pinAddresses, GCHandleType.Pinned);
|
||||
}
|
||||
_pinAddressesHandle = GCHandle.Alloc(_pinAddresses, GCHandleType.Pinned);
|
||||
}
|
||||
|
||||
~UnsafeArray2D()
|
||||
{
|
||||
_pinAddressesHandle.Free();
|
||||
}
|
||||
~UnsafeArray2D()
|
||||
{
|
||||
_pinAddressesHandle.Free();
|
||||
}
|
||||
|
||||
public void* ToPointer() => _pinAddressesHandle.AddrOfPinnedObject().ToPointer();
|
||||
public void* ToPointer() => _pinAddressesHandle.AddrOfPinnedObject().ToPointer();
|
||||
|
||||
public static implicit operator void*(UnsafeArray2D<T> array)
|
||||
{
|
||||
return array.ToPointer();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static implicit operator void*(UnsafeArray2D<T> array)
|
||||
{
|
||||
return array.ToPointer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace SabreTools.IO.Compression.zlib
|
||||
{
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace SabreTools.IO.Compression.zlib
|
||||
{
|
||||
|
||||
@@ -3070,7 +3070,7 @@ namespace SabreTools.IO.Compression.zlib
|
||||
public static int deflateSetDictionary(z_stream_s strm, byte* dictionary, uint dictLength)
|
||||
{
|
||||
internal_state? s;
|
||||
uint str = 0; uint n = 0 ;
|
||||
uint str = 0; uint n = 0 ;
|
||||
int wrap = 0;
|
||||
uint avail = 0;
|
||||
byte* next;
|
||||
@@ -3270,7 +3270,7 @@ namespace SabreTools.IO.Compression.zlib
|
||||
public static uint deflateBound(z_stream_s strm, uint sourceLen)
|
||||
{
|
||||
internal_state? s;
|
||||
uint complen = 0; uint wraplen = 0 ;
|
||||
uint complen = 0; uint wraplen = 0 ;
|
||||
complen = (uint)(sourceLen + ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5);
|
||||
if ((deflateStateCheck(strm)) != 0)
|
||||
return (uint)(complen + 6);
|
||||
@@ -4452,7 +4452,7 @@ namespace SabreTools.IO.Compression.zlib
|
||||
|
||||
public static uint multmodp(uint a, uint b)
|
||||
{
|
||||
uint m = 0; uint p = 0 ;
|
||||
uint m = 0; uint p = 0 ;
|
||||
m = (uint)((uint)(1) << 31);
|
||||
p = (uint)(0);
|
||||
for (;;)
|
||||
@@ -4559,7 +4559,7 @@ namespace SabreTools.IO.Compression.zlib
|
||||
|
||||
public static void _tr_flush_block(internal_state s, sbyte* buf, uint stored_len, int last)
|
||||
{
|
||||
uint opt_lenb = 0; uint static_lenb = 0 ;
|
||||
uint opt_lenb = 0; uint static_lenb = 0 ;
|
||||
int max_blindex = (int)(0);
|
||||
if ((s.level) > (0))
|
||||
{
|
||||
@@ -4819,7 +4819,7 @@ namespace SabreTools.IO.Compression.zlib
|
||||
int _base_ = (int)(desc.stat_desc.extra_base);
|
||||
int max_length = (int)(desc.stat_desc.max_length);
|
||||
int h = 0;
|
||||
int n = 0; int m = 0 ;
|
||||
int n = 0; int m = 0 ;
|
||||
int bits = 0;
|
||||
int xbits = 0;
|
||||
ushort f = 0;
|
||||
@@ -4836,7 +4836,7 @@ namespace SabreTools.IO.Compression.zlib
|
||||
bits = (int)(tree[tree[n].dl.dad].dl.len + 1);
|
||||
if ((bits) > (max_length))
|
||||
{
|
||||
bits = (int)(max_length); //Nanook ,
|
||||
bits = (int)(max_length); //Nanook ,
|
||||
overflow++;
|
||||
}
|
||||
tree[n].dl.len = ((ushort)(bits));
|
||||
@@ -4913,11 +4913,11 @@ namespace SabreTools.IO.Compression.zlib
|
||||
ct_data_s[] tree = desc.dyn_tree!;
|
||||
ct_data_s[] stree = desc.stat_desc.static_tree;
|
||||
int elems = (int)(desc.stat_desc.elems);
|
||||
int n = 0; int m = 0 ;
|
||||
int n = 0; int m = 0 ;
|
||||
int max_code = (int)(-1);
|
||||
int node = 0;
|
||||
s.heap_len = (int)(0); //Nanook ,
|
||||
s.heap_max = (int)(2 * (256 + 1 + 29) + 1);
|
||||
s.heap_max = (int)(2 * (256 + 1 + 29) + 1);
|
||||
for (n = (int)(0); (n) < (elems); n++)
|
||||
{
|
||||
if (tree[n].fc.freq != 0)
|
||||
@@ -4984,7 +4984,7 @@ namespace SabreTools.IO.Compression.zlib
|
||||
if ((nextlen) == (0))
|
||||
{
|
||||
max_count = (int)(138); //Nanook ,
|
||||
min_count = ( int ) ( 3 ) ;
|
||||
min_count = ( int ) ( 3 ) ;
|
||||
}
|
||||
tree[max_code + 1].dl.len = ((ushort)(0xffff));
|
||||
for (n = (int)(0); (n) <= (max_code); n++)
|
||||
@@ -5018,17 +5018,17 @@ namespace SabreTools.IO.Compression.zlib
|
||||
prevlen = (int)(curlen);
|
||||
if ((nextlen) == (0))
|
||||
{
|
||||
max_count = (int)(138); //Nanook ,
|
||||
max_count = (int)(138); //Nanook ,
|
||||
min_count = (int)(3);
|
||||
}
|
||||
else if ((curlen) == (nextlen))
|
||||
{
|
||||
max_count = (int)(6); //Nanook ,
|
||||
max_count = (int)(6); //Nanook ,
|
||||
min_count = (int)(3);
|
||||
}
|
||||
else
|
||||
{
|
||||
max_count = (int)(7); //Nanook ,
|
||||
max_count = (int)(7); //Nanook ,
|
||||
min_count = (int)(4);
|
||||
}
|
||||
}
|
||||
@@ -5045,7 +5045,7 @@ namespace SabreTools.IO.Compression.zlib
|
||||
int min_count = (int)(4);
|
||||
if ((nextlen) == (0))
|
||||
{
|
||||
max_count = (int)(138); //Nanook ,
|
||||
max_count = (int)(138); //Nanook ,
|
||||
min_count = (int)(3);
|
||||
}
|
||||
for (n = (int)(0); (n) <= (max_code); n++)
|
||||
@@ -5286,17 +5286,17 @@ namespace SabreTools.IO.Compression.zlib
|
||||
prevlen = (int)(curlen);
|
||||
if ((nextlen) == (0))
|
||||
{
|
||||
max_count = (int)(138); //Nanook ,
|
||||
max_count = (int)(138); //Nanook ,
|
||||
min_count = (int)(3);
|
||||
}
|
||||
else if ((curlen) == (nextlen))
|
||||
{
|
||||
max_count = (int)(6); //Nanook ,
|
||||
max_count = (int)(6); //Nanook ,
|
||||
min_count = (int)(3);
|
||||
}
|
||||
else
|
||||
{
|
||||
max_count = (int)(7); //Nanook ,
|
||||
max_count = (int)(7); //Nanook ,
|
||||
min_count = (int)(4);
|
||||
}
|
||||
}
|
||||
@@ -5648,7 +5648,7 @@ namespace SabreTools.IO.Compression.zlib
|
||||
do
|
||||
{
|
||||
res |= (uint)(code & 1);
|
||||
code >>= 1; //Nanook ,
|
||||
code >>= 1; //Nanook ,
|
||||
res <<= 1;
|
||||
}
|
||||
while ((--len) > (0));
|
||||
@@ -5721,7 +5721,7 @@ namespace SabreTools.IO.Compression.zlib
|
||||
|
||||
public static void slide_hash(internal_state s)
|
||||
{
|
||||
uint n = 0; uint m = 0 ;
|
||||
uint n = 0; uint m = 0 ;
|
||||
ushort* p;
|
||||
uint wsize = (uint)(s.w_size);
|
||||
n = (uint)(s.hash_size);
|
||||
@@ -5823,7 +5823,7 @@ namespace SabreTools.IO.Compression.zlib
|
||||
public static block_state deflate_stored(internal_state s, int flush)
|
||||
{
|
||||
uint min_block = (uint)((s.pending_buf_size - 5) > (s.w_size) ? (s.w_size) : (s.pending_buf_size - 5));
|
||||
uint len = 0; uint left = 0 ; uint have = 0 ; uint last = ( uint ) ( 0 ) ;
|
||||
uint len = 0; uint left = 0 ; uint have = 0 ; uint last = ( uint ) ( 0 ) ;
|
||||
uint used = (uint)(s.strm!.avail_in);
|
||||
do
|
||||
{
|
||||
@@ -6096,7 +6096,7 @@ namespace SabreTools.IO.Compression.zlib
|
||||
s.head[s.ins_h] = ((ushort)(s.strstart));
|
||||
}
|
||||
|
||||
s.prev_length = (uint)(s.match_length); //Nanook ,
|
||||
s.prev_length = (uint)(s.match_length); //Nanook ,
|
||||
s.prev_match = (uint)(s.match_start);
|
||||
s.match_length = (uint)(3 - 1);
|
||||
if (((hash_head != 0) && ((s.prev_length) < (s.max_lazy_match))) && ((s.strstart - hash_head) <= ((s).w_size - (258 + 3 + 1))))
|
||||
@@ -6233,7 +6233,7 @@ namespace SabreTools.IO.Compression.zlib
|
||||
{
|
||||
int bflush = 0;
|
||||
uint prev = 0;
|
||||
byte* scan; byte * strend ;
|
||||
byte* scan; byte * strend ;
|
||||
for (;;)
|
||||
{
|
||||
if ((s.lookahead) <= (258))
|
||||
@@ -6521,7 +6521,7 @@ namespace SabreTools.IO.Compression.zlib
|
||||
match = s.window + cur_match;
|
||||
if ((((match[best_len] != scan_end) || (match[best_len - 1] != scan_end1)) || (*match != *scan)) || (*++match != scan[1]))
|
||||
continue;
|
||||
scan += 2; //Nanook ,
|
||||
scan += 2; //Nanook ,
|
||||
match++;
|
||||
do
|
||||
{
|
||||
|
||||
@@ -44,4 +44,4 @@ namespace SabreTools.IO.Compression.zlib
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,4 +122,4 @@ namespace SabreTools.IO.Encryption
|
||||
progress?.Invoke($"{blockCount + 1} / {blockCount + 1} MB... Done!\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.Hashing;
|
||||
using SabreTools.IO.Extensions;
|
||||
|
||||
@@ -12,6 +13,86 @@ namespace SabreTools.IO.Encryption
|
||||
{
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// Converts ASCII characters to lowercase
|
||||
/// </summary>
|
||||
/// <remarks>Converts slash (0x2F) to backslash (0x5C)</remarks>
|
||||
private static readonly byte[] AsciiToLowerTable =
|
||||
[
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x5C,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
|
||||
0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
|
||||
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
|
||||
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
|
||||
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
|
||||
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
|
||||
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Converts ASCII characters to uppercase
|
||||
/// </summary>
|
||||
/// <remarks>Converts slash (0x2F) to backslash (0x5C)</remarks>
|
||||
private static readonly byte[] AsciiToUpperTable =
|
||||
[
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x5C,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
|
||||
0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
|
||||
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
|
||||
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
|
||||
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
|
||||
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
|
||||
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Converts ASCII characters to uppercase
|
||||
/// </summary>
|
||||
/// <remarks>Does NOT convert slash (0x2F) to backslash (0x5C)</remarks>
|
||||
private static readonly byte[] AsciiToUpperTable_Slash =
|
||||
[
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
|
||||
0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
|
||||
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
|
||||
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
|
||||
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
|
||||
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
|
||||
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
|
||||
];
|
||||
|
||||
private const uint MPQ_HASH_TABLE_INDEX = 0x000;
|
||||
|
||||
private const uint MPQ_HASH_NAME_A = 0x100;
|
||||
|
||||
private const uint MPQ_HASH_NAME_B = 0x200;
|
||||
|
||||
private const uint MPQ_HASH_FILE_KEY = 0x300;
|
||||
|
||||
private const uint MPQ_HASH_KEY2_MIX = 0x400;
|
||||
|
||||
private const uint STORM_BUFFER_SIZE = 0x500;
|
||||
@@ -175,5 +256,108 @@ namespace SabreTools.IO.Encryption
|
||||
Buffer.BlockCopy(castBlock, 0, block, 0, block.Length >> 2);
|
||||
return block;
|
||||
}
|
||||
|
||||
#region Hashing
|
||||
|
||||
//
|
||||
// Note: Implementation of this function in WorldEdit.exe and storm.dll
|
||||
// incorrectly treats the character as signed, which leads to the
|
||||
// a buffer underflow if the character in the file name >= 0x80:
|
||||
// The following steps happen when *pbKey == 0xBF and hashType == 0x0000
|
||||
// (calculating hash index)
|
||||
//
|
||||
// 1) Result of AsciiToUpperTable_Slash[*pbKey++] is sign-extended to 0xffffffbf
|
||||
// 2) The "ch" is added to hashType (0xffffffbf + 0x0000 => 0xffffffbf)
|
||||
// 3) The result is used as index to the StormBuffer table,
|
||||
// thus dereferences a random value BEFORE the begin of StormBuffer.
|
||||
//
|
||||
// As result, MPQs containing files with non-ANSI characters will not work between
|
||||
// various game versions and localizations. Even WorldEdit, after importing a file
|
||||
// with Korean characters in the name, cannot open the file back.
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// Hash a string representing a filename based on the hash type
|
||||
/// using upper-case normalization
|
||||
/// </summary>
|
||||
/// <param name="filename">Filename to hash</param>
|
||||
/// <param name="hashType">Hash type to perform</param>
|
||||
/// <returns>Value representing the hashed filename</returns>
|
||||
public uint HashString(string filename, uint hashType)
|
||||
{
|
||||
uint seed1 = 0x7FED7FED;
|
||||
uint seed2 = 0xEEEEEEEE;
|
||||
|
||||
byte[] key = Encoding.ASCII.GetBytes(filename);
|
||||
int keyPtr = 0;
|
||||
while (key[keyPtr] != 0)
|
||||
{
|
||||
// Convert the input character to uppercase
|
||||
// Convert slash (0x2F) to backslash (0x5C)
|
||||
byte ch = AsciiToUpperTable[key[keyPtr++]];
|
||||
|
||||
seed1 = _stormBuffer[hashType + ch] ^ (seed1 + seed2);
|
||||
seed2 = ch + seed1 + seed2 + (seed2 << 5) + 3;
|
||||
}
|
||||
|
||||
return seed1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hash a string representing a filename based on the hash type
|
||||
/// using upper-case normalization
|
||||
/// </summary>
|
||||
/// <param name="filename">Filename to hash</param>
|
||||
/// <param name="hashType">Hash type to perform</param>
|
||||
/// <returns>Value representing the hashed filename</returns>
|
||||
/// <remarks>This preserves slashes when hashing</remarks>
|
||||
public uint HashStringSlash(string filename, uint hashType)
|
||||
{
|
||||
uint seed1 = 0x7FED7FED;
|
||||
uint seed2 = 0xEEEEEEEE;
|
||||
|
||||
byte[] key = Encoding.ASCII.GetBytes(filename);
|
||||
int keyPtr = 0;
|
||||
while (key[keyPtr] != 0)
|
||||
{
|
||||
// Convert the input character to uppercase
|
||||
// DON'T convert slash (0x2F) to backslash (0x5C)
|
||||
byte ch = AsciiToUpperTable_Slash[key[keyPtr++]];
|
||||
|
||||
seed1 = _stormBuffer[hashType + ch] ^ (seed1 + seed2);
|
||||
seed2 = ch + seed1 + seed2 + (seed2 << 5) + 3;
|
||||
}
|
||||
|
||||
return seed1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hash a string representing a filename based on the hash type
|
||||
/// using lower-case normalization
|
||||
/// </summary>
|
||||
/// <param name="filename">Filename to hash</param>
|
||||
/// <param name="hashType">Hash type to perform</param>
|
||||
/// <returns>Value representing the hashed filename</returns>
|
||||
public uint HashStringLower(string filename, uint hashType)
|
||||
{
|
||||
uint seed1 = 0x7FED7FED;
|
||||
uint seed2 = 0xEEEEEEEE;
|
||||
|
||||
byte[] key = Encoding.ASCII.GetBytes(filename);
|
||||
int keyPtr = 0;
|
||||
while (key[keyPtr] != 0)
|
||||
{
|
||||
// Convert the input character to lower
|
||||
// DON'T convert slash (0x2F) to backslash (0x5C)
|
||||
byte ch = AsciiToLowerTable[key[keyPtr++]];
|
||||
|
||||
seed1 = _stormBuffer[hashType + ch] ^ (seed1 + seed2);
|
||||
seed2 = ch + seed1 + seed2 + (seed2 << 5) + 3;
|
||||
}
|
||||
|
||||
return seed1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
|
||||
internal sealed class ExtensionAttribute : Attribute {}
|
||||
internal sealed class ExtensionAttribute : Attribute { }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -683,8 +683,7 @@ namespace SabreTools.IO.Extensions
|
||||
return false;
|
||||
|
||||
// Get the array
|
||||
Array? arr = fi.GetValue(instance) as Array;
|
||||
if (arr == null)
|
||||
if (fi.GetValue(instance) is not Array arr)
|
||||
return false;
|
||||
|
||||
// Get the number of elements expected
|
||||
@@ -712,8 +711,7 @@ namespace SabreTools.IO.Extensions
|
||||
private static bool WriteStringType(BinaryWriter writer, Encoding encoding, object instance, FieldInfo fi)
|
||||
{
|
||||
var marshalAsAttr = MarshalHelpers.GetAttribute<MarshalAsAttribute>(fi);
|
||||
string? fieldValue = fi.GetValue(instance) as string;
|
||||
if (fieldValue == null)
|
||||
if (fi.GetValue(instance) is not string fieldValue)
|
||||
return true;
|
||||
|
||||
switch (marshalAsAttr?.Value)
|
||||
|
||||
@@ -16,6 +16,19 @@ namespace SabreTools.IO.Extensions
|
||||
return array == null || array.Length == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if an array contains all ASCII numeric digits
|
||||
/// </summary>
|
||||
public static bool IsNumericArray(this byte[] arr)
|
||||
{
|
||||
// Empty arrays cannot be numeric
|
||||
if (arr.Length == 0)
|
||||
return false;
|
||||
|
||||
// '0' to '9'
|
||||
return Array.TrueForAll(arr, b => b >= 0x30 && b <= 0x39);
|
||||
}
|
||||
|
||||
#region Matching
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -852,8 +852,7 @@ namespace SabreTools.IO.Extensions
|
||||
return false;
|
||||
|
||||
// Get the array
|
||||
Array? arr = fi.GetValue(instance) as Array;
|
||||
if (arr == null)
|
||||
if (fi.GetValue(instance) is not Array arr)
|
||||
return false;
|
||||
|
||||
// Get the number of elements expected
|
||||
@@ -881,8 +880,7 @@ namespace SabreTools.IO.Extensions
|
||||
private static bool WriteStringType(byte[] content, ref int offset, Encoding encoding, object instance, FieldInfo fi)
|
||||
{
|
||||
var marshalAsAttr = MarshalHelpers.GetAttribute<MarshalAsAttribute>(fi);
|
||||
string? fieldValue = fi.GetValue(instance) as string;
|
||||
if (fieldValue == null)
|
||||
if (fi.GetValue(instance) is not string fieldValue)
|
||||
return true;
|
||||
|
||||
switch (marshalAsAttr?.Value)
|
||||
|
||||
33
SabreTools.IO/Extensions/DictionaryExtensions.cs
Normal file
33
SabreTools.IO/Extensions/DictionaryExtensions.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SabreTools.IO.Extensions
|
||||
{
|
||||
public static class DictionaryExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Merge a dictionary into an existing one, if possible
|
||||
/// </summary>
|
||||
/// <param name="dict">Source dictionary to add to</param>
|
||||
/// <param name="other">Second dictionary to add from</param>
|
||||
/// <remarks>This only performs a shallow copy</remarks>
|
||||
public static void MergeWith(this Dictionary<string, List<string>> dict, Dictionary<string, List<string>> other)
|
||||
{
|
||||
// Ignore if there are no values to append
|
||||
if (other.Count == 0)
|
||||
return;
|
||||
|
||||
// Loop through and add from the new dictionary
|
||||
foreach (var kvp in other)
|
||||
{
|
||||
// Ignore empty values
|
||||
if (kvp.Value.Count == 0)
|
||||
continue;
|
||||
|
||||
if (!dict.ContainsKey(kvp.Key))
|
||||
dict[kvp.Key] = [];
|
||||
|
||||
dict[kvp.Key].AddRange(kvp.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,37 +14,37 @@ namespace SabreTools.IO.Extensions
|
||||
/// <summary>
|
||||
/// Get an attribute of the requested type
|
||||
/// </summary>
|
||||
public static T? GetAttribute<T>(FieldInfo? fi) where T : Attribute
|
||||
public static TAttribute? GetAttribute<TAttribute>(FieldInfo? fi) where TAttribute : Attribute
|
||||
{
|
||||
// If the field info is invalid
|
||||
if (fi == null)
|
||||
return null;
|
||||
|
||||
// Get all matching attributes
|
||||
var attributes = fi.GetCustomAttributes(typeof(T), true);
|
||||
var attributes = fi.GetCustomAttributes(typeof(TAttribute), true);
|
||||
if (attributes == null || attributes.Length == 0)
|
||||
return null;
|
||||
|
||||
// Get the first attribute that matches
|
||||
return attributes[0] as T;
|
||||
return attributes[0] as TAttribute;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get an attribute of the requested type
|
||||
/// </summary>
|
||||
public static T? GetAttribute<T>(Type? type) where T : Attribute
|
||||
public static TAttribute? GetAttribute<TAttribute>(Type? type) where TAttribute : Attribute
|
||||
{
|
||||
// If the field info is invalid
|
||||
if (type == null)
|
||||
return null;
|
||||
|
||||
// Get all matching attributes
|
||||
var attributes = type.GetCustomAttributes(typeof(T), true);
|
||||
var attributes = type.GetCustomAttributes(typeof(TAttribute), true);
|
||||
if (attributes == null || attributes.Length == 0)
|
||||
return null;
|
||||
|
||||
// Get the first attribute that matches
|
||||
return attributes[0] as T;
|
||||
return attributes[0] as TAttribute;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -853,8 +853,7 @@ namespace SabreTools.IO.Extensions
|
||||
return false;
|
||||
|
||||
// Get the array
|
||||
Array? arr = fi.GetValue(instance) as Array;
|
||||
if (arr == null)
|
||||
if (fi.GetValue(instance) is not Array arr)
|
||||
return false;
|
||||
|
||||
// Get the number of elements expected
|
||||
@@ -883,8 +882,7 @@ namespace SabreTools.IO.Extensions
|
||||
private static bool WriteStringType(Stream stream, Encoding encoding, object instance, FieldInfo fi)
|
||||
{
|
||||
var marshalAsAttr = MarshalHelpers.GetAttribute<MarshalAsAttribute>(fi);
|
||||
string? fieldValue = fi.GetValue(instance) as string;
|
||||
if (fieldValue == null)
|
||||
if (fi.GetValue(instance) is not string fieldValue)
|
||||
return true;
|
||||
|
||||
switch (marshalAsAttr?.Value)
|
||||
|
||||
@@ -60,4 +60,4 @@ namespace SabreTools.IO.Extensions
|
||||
return self.StartsWith(value, comparisonType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace SabreTools.IO.Logging
|
||||
// Set the log directory
|
||||
LogDirectory = Path.GetDirectoryName(fullPath);
|
||||
|
||||
// Set the
|
||||
// Set the
|
||||
if (addDate)
|
||||
Filename = $"{Path.GetFileNameWithoutExtension(fullPath)} ({DateTime.Now:yyyy-MM-dd HH-mm-ss}).{fullPath.GetNormalizedExtension()}";
|
||||
else
|
||||
|
||||
@@ -71,12 +71,12 @@ namespace SabreTools.IO.Matching
|
||||
/// <summary>
|
||||
/// Allow conversion from byte array to ContentMatch
|
||||
/// </summary>
|
||||
public static implicit operator ContentMatch(byte[] needle) => new ContentMatch(needle);
|
||||
public static implicit operator ContentMatch(byte[] needle) => new(needle);
|
||||
|
||||
/// <summary>
|
||||
/// Allow conversion from nullable byte array to ContentMatch
|
||||
/// </summary>
|
||||
public static implicit operator ContentMatch(byte?[] needle) => new ContentMatch(needle);
|
||||
public static implicit operator ContentMatch(byte?[] needle) => new(needle);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace SabreTools.IO.Matching
|
||||
/// <summary>
|
||||
/// Allow conversion from string to PathMatch
|
||||
/// </summary>
|
||||
public static implicit operator PathMatch(string needle) => new PathMatch(needle);
|
||||
public static implicit operator PathMatch(string needle) => new(needle);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1,234 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace SabreTools.Numerics
|
||||
{
|
||||
/// <summary>
|
||||
/// Both-endian numeric value
|
||||
/// </summary>
|
||||
public abstract class BothEndian<T>(T le, T be) : IComparable, IConvertible, IEquatable<BothEndian<T>>, IEquatable<T>
|
||||
where T : notnull, IComparable, IConvertible, IEquatable<T>
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Little-endian representation of the number
|
||||
/// </summary>
|
||||
/// <remarks>Value should match <see cref="BigEndian"/></remarks>
|
||||
public readonly T LittleEndian = le;
|
||||
|
||||
/// <summary>
|
||||
/// Big-endian representation of the number
|
||||
/// </summary>
|
||||
/// <remarks>Value should match <see cref="LittleEndian"/></remarks>
|
||||
public readonly T BigEndian = be;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the value is valid
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Validity of a both-endian value is determined based on if both
|
||||
/// endianness values match. These values should always match, based
|
||||
/// on all implementations.
|
||||
/// </remarks>
|
||||
public bool IsValid => LittleEndian.Equals(BigEndian);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <remarks>
|
||||
/// Returns either <see cref="LittleEndian"/> or <see cref="BigEndian"/>
|
||||
/// depending on the system endianness.
|
||||
/// </remarks>
|
||||
public static implicit operator T(BothEndian<T> val)
|
||||
=> BitConverter.IsLittleEndian ? val.LittleEndian : val.BigEndian;
|
||||
|
||||
public static bool operator ==(BothEndian<T> a, BothEndian<T> b) => a.Equals(b);
|
||||
|
||||
public static bool operator !=(BothEndian<T> a, BothEndian<T> b) => !a.Equals(b);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Object
|
||||
|
||||
#if NETCOREAPP
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is BothEndian<T> be)
|
||||
return Equals(be);
|
||||
|
||||
if (obj is T t)
|
||||
return Equals(t);
|
||||
|
||||
return base.Equals(obj);
|
||||
}
|
||||
#else
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is BothEndian<T> be)
|
||||
return Equals(be);
|
||||
|
||||
if (obj is T t)
|
||||
return Equals(t);
|
||||
|
||||
return base.Equals(obj);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode() => ((T)this).GetHashCode();
|
||||
|
||||
#if NETCOREAPP
|
||||
/// <inheritdoc/>
|
||||
public override string? ToString() => ((T)this).ToString();
|
||||
#else
|
||||
/// <inheritdoc/>
|
||||
public override string ToString() => ((T)this).ToString();
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#region IComparable
|
||||
|
||||
/// <inheritdoc/>
|
||||
#if NETCOREAPP
|
||||
public int CompareTo(object? obj) => ((T)this).CompareTo(obj);
|
||||
#else
|
||||
public int CompareTo(object obj) => ((T)this).CompareTo(obj);
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#region IConvertible
|
||||
|
||||
/// <inheritdoc/>
|
||||
public TypeCode GetTypeCode() => ((T)this).GetTypeCode();
|
||||
|
||||
#if NETCOREAPP
|
||||
/// <inheritdoc/>
|
||||
public bool ToBoolean(IFormatProvider? provider) => ((T)this).ToBoolean(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public char ToChar(IFormatProvider? provider) => ((T)this).ToChar(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public sbyte ToSByte(IFormatProvider? provider) => ((T)this).ToSByte(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public byte ToByte(IFormatProvider? provider) => ((T)this).ToByte(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public short ToInt16(IFormatProvider? provider) => ((T)this).ToInt16(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ushort ToUInt16(IFormatProvider? provider) => ((T)this).ToUInt16(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int ToInt32(IFormatProvider? provider) => ((T)this).ToInt32(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public uint ToUInt32(IFormatProvider? provider) => ((T)this).ToUInt32(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public long ToInt64(IFormatProvider? provider) => ((T)this).ToInt64(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ulong ToUInt64(IFormatProvider? provider) => ((T)this).ToUInt64(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float ToSingle(IFormatProvider? provider) => ((T)this).ToSingle(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public double ToDouble(IFormatProvider? provider) => ((T)this).ToDouble(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public decimal ToDecimal(IFormatProvider? provider) => ((T)this).ToDecimal(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTime ToDateTime(IFormatProvider? provider) => ((T)this).ToDateTime(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string ToString(IFormatProvider? provider) => ((T)this).ToString(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public object ToType(Type conversionType, IFormatProvider? provider) => ((T)this).ToType(conversionType, provider);
|
||||
#else
|
||||
/// <inheritdoc/>
|
||||
public bool ToBoolean(IFormatProvider provider) => ((T)this).ToBoolean(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public char ToChar(IFormatProvider provider) => ((T)this).ToChar(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public sbyte ToSByte(IFormatProvider provider) => ((T)this).ToSByte(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public byte ToByte(IFormatProvider provider) => ((T)this).ToByte(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public short ToInt16(IFormatProvider provider) => ((T)this).ToInt16(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ushort ToUInt16(IFormatProvider provider) => ((T)this).ToUInt16(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int ToInt32(IFormatProvider provider) => ((T)this).ToInt32(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public uint ToUInt32(IFormatProvider provider) => ((T)this).ToUInt32(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public long ToInt64(IFormatProvider provider) => ((T)this).ToInt64(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ulong ToUInt64(IFormatProvider provider) => ((T)this).ToUInt64(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float ToSingle(IFormatProvider provider) => ((T)this).ToSingle(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public double ToDouble(IFormatProvider provider) => ((T)this).ToDouble(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public decimal ToDecimal(IFormatProvider provider) => ((T)this).ToDecimal(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTime ToDateTime(IFormatProvider provider) => ((T)this).ToDateTime(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string ToString(IFormatProvider provider) => ((T)this).ToString(provider);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public object ToType(Type conversionType, IFormatProvider provider) => ((T)this).ToType(conversionType, provider);
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable
|
||||
|
||||
#if NETCOREAPP
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(BothEndian<T>? other)
|
||||
{
|
||||
if (other is null)
|
||||
return false;
|
||||
|
||||
return LittleEndian.Equals(other.LittleEndian) && BigEndian.Equals(other.BigEndian);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(T? other) => ((T)this).Equals(other);
|
||||
#else
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(BothEndian<T> other)
|
||||
=> LittleEndian.Equals(other.LittleEndian) && BigEndian.Equals(other.BigEndian);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(T other) => ((T)this).Equals(other);
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -47,4 +47,4 @@ namespace SabreTools.IO
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user