Skip to content

Commit 9ed6fb6

Browse files
committed
noseek option, small fixes
1 parent 9b50662 commit 9ed6fb6

File tree

7 files changed

+50
-8
lines changed

7 files changed

+50
-8
lines changed

Blazer.Net.Tests/OptionsTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,5 +195,27 @@ public void Comment_Should_Be_Stored()
195195
var os = new BlazerOutputStream(new MemoryStream(compressed));
196196
Assert.That(os.Comment, Is.EqualTo("Test Comment Юникоде"));
197197
}
198+
199+
[Test]
200+
public void NoSeek_Should_Be_Respected()
201+
{
202+
var data1 = new byte[12];
203+
var blazerCompressionOptions = BlazerCompressionOptions.CreateStream();
204+
blazerCompressionOptions.LeaveStreamOpen = true;
205+
var ms1 = new MemoryStream();
206+
// default flush respected
207+
using (var b = new BlazerInputStream(ms1, blazerCompressionOptions))
208+
{
209+
b.Write(data1, 0, data1.Length);
210+
}
211+
212+
var arr = ms1.ToArray();
213+
// footer now invalid
214+
arr[arr.Length - 3] = 0;
215+
216+
Assert.Throws<InvalidOperationException>(() => new BlazerOutputStream(new MemoryStream(arr)));
217+
218+
Assert.DoesNotThrow(() => new BlazerOutputStream(new MemoryStream(arr), new BlazerDecompressionOptions() { NoSeek = true }));
219+
}
198220
}
199221
}

Blazer.Net/Algorithms/Patterned/BasePatternedCompressor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public void PreparePattern(byte[] pattern, int offset, int count)
6363
InitHashArray();
6464
}
6565

66+
/// <summary>
67+
/// Prepares pattern. Should be called only once for one pattern
68+
/// </summary>
6669
public void PreparePattern(byte[] pattern)
6770
{
6871
PreparePattern(pattern, 0, pattern.Length);

Blazer.Net/Blazer.Net.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
<UseVSHostingProcess>false</UseVSHostingProcess>
2424
</PropertyGroup>
2525
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26-
<DebugType>pdbonly</DebugType>
26+
<DebugType>none</DebugType>
2727
<Optimize>true</Optimize>
2828
<OutputPath>bin\Release\</OutputPath>
2929
<DefineConstants>TRACE</DefineConstants>
3030
<ErrorReport>prompt</ErrorReport>
3131
<WarningLevel>4</WarningLevel>
3232
<UseVSHostingProcess>false</UseVSHostingProcess>
33-
<DocumentationFile>bin\Release\Blazer.Net.XML</DocumentationFile>
33+
<DocumentationFile>bin\Release\Blazer.Net.xml</DocumentationFile>
3434
</PropertyGroup>
3535
<PropertyGroup>
3636
<SignAssembly>true</SignAssembly>

Blazer.Net/Blazer.Net.nuspec

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,31 @@
33
<metadata>
44
<id>Blazer.Net</id>
55
<title>Blazer.Net</title>
6-
<version>0.8.1</version>
6+
<version>0.9.0</version>
77
<authors>force</authors>
88
<owners>force</owners>
99
<licenseUrl>https://github.com/force-net/blazer/blob/develop/LICENSE</licenseUrl>
1010
<projectUrl>https://github.com/force-net/blazer</projectUrl>
1111
<!--iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl-->
1212
<requireLicenseAcceptance>false</requireLicenseAcceptance>
13+
<summary>Blazer is high-performance, low compression archiver.</summary>
1314
<description>
1415
Blazer is high-performance, low compression archiver.
15-
Main usage to work with streams, but can be used as general archiver or as application resource helper.
16+
Main usage to work with streams, but can be used as general archiver or for reducing application size by compressing it resources.
1617
Compression rate is comparable (slightly better) to LZ4 and Snappy and compression speed is really faster than GZip.
18+
Blazer contains all standard features for archives, but also it is possible to use control commands in stream, encrypt archive, use it as simple (but fast) crc32c calulator, perform patterned compresstion and many others features.
19+
20+
See project site for detailed information.
1721
</description>
1822
<releaseNotes>
19-
Added Comment option for archive, more information about archive on decompression, fixed some bugs.
23+
Fixed bugs
24+
Added some helper methods for compression
25+
Improved Crc32C api to use it in external applications if needed (instead of separate library)
26+
NoSeek option for decryption
27+
Mega-feature: patterned compression, which can reduce compressed size of similar small messages
2028
</releaseNotes>
2129
<copyright>Copyright by Force 2016</copyright>
22-
<tags>.NET fast compression archive</tags>
30+
<tags>.NET fast compression archive crc32c</tags>
2331
</metadata>
2432
<files><file src="bin\Release\Blazer.Net.*" target="lib\net40" /></files>
2533
</package>

Blazer.Net/BlazerDecompressionOptions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public void SetDecoderByAlgorithm(BlazerAlgorithm algorithm)
4242
/// </summary>
4343
public bool EncyptFull { get; set; }
4444

45+
/// <summary>
46+
/// Disable seeking for inner stream
47+
/// </summary>
48+
/// <remarks>By default, <see cref="BlazerOutputStream"/> checks is stream seekable. But with this flag this check can be disabled and seek will not be performed for any stream</remarks>
49+
public bool NoSeek { get; set; }
50+
4551
/// <summary>
4652
/// Callback on control data block. If is set, will be called for every control data
4753
/// </summary>

Blazer.Net/BlazerOutputStream.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ public override long Position
135135

136136
private bool _shouldHaveComment;
137137

138+
private readonly bool _noSeek;
139+
138140
private string _comment;
139141

140142
private NullDecryptHelper _decryptHelper;
@@ -202,6 +204,7 @@ public BlazerOutputStream(Stream innerStream, BlazerDecompressionOptions options
202204

203205
var password = options.Password;
204206
_controlDataCallback = options.ControlDataCallback ?? ((b, o, c) => { });
207+
_noSeek = options.NoSeek;
205208

206209
if (options.EncyptFull)
207210
{
@@ -406,7 +409,7 @@ private void ReadAndValidateHeader()
406409

407410
_innerBuffer = new byte[_maxUncompressedBlockSize];
408411

409-
if (_includeFooter && _innerStream.CanSeek)
412+
if (_includeFooter && _innerStream.CanSeek && !_noSeek)
410413
{
411414
var position = _innerStream.Seek(0, SeekOrigin.Current);
412415
_innerStream.Seek(-4, SeekOrigin.End);

Doc/PatternedCompression.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Compression with preliminary pattern
22

3-
Imagine, you have lot of similar data. This data can be log messages, soap integration xmls, status logs. And you want to save this data **independently** (if you don't need to do this, you can compress all messages into solid archive. It is best variant for compression, but as result all messages should be extracted if only one needed for view).
3+
Imagine, you have lot of similar data. This data can be log messages, SOAP integration XMLs, status logs. And you want to save this data **independently** (if you don't need to do this, you can compress all messages into solid archive. It is best variant for compression, but as result all messages should be extracted if only one needed for view).
44
These messages can be stored in file system or database, but you want to store each message separately to keep fast access to it.
55

66
You want to compress this messages to save storage, but these messages are small and compress not very good as result.

0 commit comments

Comments
 (0)