Skip to content

Commit

Permalink
noseek option, small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
force-net committed Aug 25, 2016
1 parent 9b50662 commit 9ed6fb6
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 8 deletions.
22 changes: 22 additions & 0 deletions Blazer.Net.Tests/OptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,27 @@ public void Comment_Should_Be_Stored()
var os = new BlazerOutputStream(new MemoryStream(compressed));
Assert.That(os.Comment, Is.EqualTo("Test Comment Юникоде"));
}

[Test]
public void NoSeek_Should_Be_Respected()
{
var data1 = new byte[12];
var blazerCompressionOptions = BlazerCompressionOptions.CreateStream();
blazerCompressionOptions.LeaveStreamOpen = true;
var ms1 = new MemoryStream();
// default flush respected
using (var b = new BlazerInputStream(ms1, blazerCompressionOptions))
{
b.Write(data1, 0, data1.Length);
}

var arr = ms1.ToArray();
// footer now invalid
arr[arr.Length - 3] = 0;

Assert.Throws<InvalidOperationException>(() => new BlazerOutputStream(new MemoryStream(arr)));

Assert.DoesNotThrow(() => new BlazerOutputStream(new MemoryStream(arr), new BlazerDecompressionOptions() { NoSeek = true }));
}
}
}
3 changes: 3 additions & 0 deletions Blazer.Net/Algorithms/Patterned/BasePatternedCompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public void PreparePattern(byte[] pattern, int offset, int count)
InitHashArray();
}

/// <summary>
/// Prepares pattern. Should be called only once for one pattern
/// </summary>
public void PreparePattern(byte[] pattern)
{
PreparePattern(pattern, 0, pattern.Length);
Expand Down
4 changes: 2 additions & 2 deletions Blazer.Net/Blazer.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
<DocumentationFile>bin\Release\Blazer.Net.XML</DocumentationFile>
<DocumentationFile>bin\Release\Blazer.Net.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
Expand Down
16 changes: 12 additions & 4 deletions Blazer.Net/Blazer.Net.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@
<metadata>
<id>Blazer.Net</id>
<title>Blazer.Net</title>
<version>0.8.1</version>
<version>0.9.0</version>
<authors>force</authors>
<owners>force</owners>
<licenseUrl>https://github.com/force-net/blazer/blob/develop/LICENSE</licenseUrl>
<projectUrl>https://github.com/force-net/blazer</projectUrl>
<!--iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl-->
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<summary>Blazer is high-performance, low compression archiver.</summary>
<description>
Blazer is high-performance, low compression archiver.
Main usage to work with streams, but can be used as general archiver or as application resource helper.
Main usage to work with streams, but can be used as general archiver or for reducing application size by compressing it resources.
Compression rate is comparable (slightly better) to LZ4 and Snappy and compression speed is really faster than GZip.
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.

See project site for detailed information.
</description>
<releaseNotes>
Added Comment option for archive, more information about archive on decompression, fixed some bugs.
Fixed bugs
Added some helper methods for compression
Improved Crc32C api to use it in external applications if needed (instead of separate library)
NoSeek option for decryption
Mega-feature: patterned compression, which can reduce compressed size of similar small messages
</releaseNotes>
<copyright>Copyright by Force 2016</copyright>
<tags>.NET fast compression archive</tags>
<tags>.NET fast compression archive crc32c</tags>
</metadata>
<files><file src="bin\Release\Blazer.Net.*" target="lib\net40" /></files>
</package>
6 changes: 6 additions & 0 deletions Blazer.Net/BlazerDecompressionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public void SetDecoderByAlgorithm(BlazerAlgorithm algorithm)
/// </summary>
public bool EncyptFull { get; set; }

/// <summary>
/// Disable seeking for inner stream
/// </summary>
/// <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>
public bool NoSeek { get; set; }

/// <summary>
/// Callback on control data block. If is set, will be called for every control data
/// </summary>
Expand Down
5 changes: 4 additions & 1 deletion Blazer.Net/BlazerOutputStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ public override long Position

private bool _shouldHaveComment;

private readonly bool _noSeek;

private string _comment;

private NullDecryptHelper _decryptHelper;
Expand Down Expand Up @@ -202,6 +204,7 @@ public BlazerOutputStream(Stream innerStream, BlazerDecompressionOptions options

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

if (options.EncyptFull)
{
Expand Down Expand Up @@ -406,7 +409,7 @@ private void ReadAndValidateHeader()

_innerBuffer = new byte[_maxUncompressedBlockSize];

if (_includeFooter && _innerStream.CanSeek)
if (_includeFooter && _innerStream.CanSeek && !_noSeek)
{
var position = _innerStream.Seek(0, SeekOrigin.Current);
_innerStream.Seek(-4, SeekOrigin.End);
Expand Down
2 changes: 1 addition & 1 deletion Doc/PatternedCompression.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Compression with preliminary pattern

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).
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).
These messages can be stored in file system or database, but you want to store each message separately to keep fast access to it.

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

0 comments on commit 9ed6fb6

Please sign in to comment.