├── .gitattributes ├── .gitignore ├── COPYING ├── README.md └── src ├── SmazSharp.nuspec ├── SmazSharp.sln ├── SmazSharp ├── Properties │ └── AssemblyInfo.cs ├── Smaz.cs ├── SmazSharp-20.csproj ├── SmazSharp-30.csproj ├── SmazSharp-35.csproj ├── SmazSharp-40.csproj └── SmazSharp.csproj └── SmazSharpTests ├── ComplianceTests.cs ├── Options.cs ├── PerformanceTests.cs ├── Program.cs ├── Properties └── AssemblyInfo.cs ├── Resources.cs ├── SmazSharpTests.csproj └── packages.config /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | bld/ 16 | [Bb]in/ 17 | [Oo]bj/ 18 | 19 | # Roslyn cache directories 20 | *.ide/ 21 | 22 | # MSTest test Results 23 | [Tt]est[Rr]esult*/ 24 | [Bb]uild[Ll]og.* 25 | 26 | #NUNIT 27 | *.VisualState.xml 28 | TestResult.xml 29 | 30 | # Build Results of an ATL Project 31 | [Dd]ebugPS/ 32 | [Rr]eleasePS/ 33 | dlldata.c 34 | 35 | *_i.c 36 | *_p.c 37 | *_i.h 38 | *.ilk 39 | *.meta 40 | *.obj 41 | *.pch 42 | *.pdb 43 | *.pgc 44 | *.pgd 45 | *.rsp 46 | *.sbr 47 | *.tlb 48 | *.tli 49 | *.tlh 50 | *.tmp 51 | *.tmp_proj 52 | *.log 53 | *.vspscc 54 | *.vssscc 55 | .builds 56 | *.pidb 57 | *.svclog 58 | *.scc 59 | 60 | # Chutzpah Test files 61 | _Chutzpah* 62 | 63 | # Visual C++ cache files 64 | ipch/ 65 | *.aps 66 | *.ncb 67 | *.opensdf 68 | *.sdf 69 | *.cachefile 70 | 71 | # Visual Studio profiler 72 | *.psess 73 | *.vsp 74 | *.vspx 75 | 76 | # TFS 2012 Local Workspace 77 | $tf/ 78 | 79 | # Guidance Automation Toolkit 80 | *.gpState 81 | 82 | # ReSharper is a .NET coding add-in 83 | _ReSharper*/ 84 | *.[Rr]e[Ss]harper 85 | *.DotSettings.user 86 | 87 | # JustCode is a .NET coding addin-in 88 | .JustCode 89 | 90 | # TeamCity is a build add-in 91 | _TeamCity* 92 | 93 | # DotCover is a Code Coverage Tool 94 | *.dotCover 95 | 96 | # NCrunch 97 | _NCrunch_* 98 | .*crunch*.local.xml 99 | 100 | # MightyMoose 101 | *.mm.* 102 | AutoTest.Net/ 103 | 104 | # Web workbench (sass) 105 | .sass-cache/ 106 | 107 | # Installshield output folder 108 | [Ee]xpress/ 109 | 110 | # DocProject is a documentation generator add-in 111 | DocProject/buildhelp/ 112 | DocProject/Help/*.HxT 113 | DocProject/Help/*.HxC 114 | DocProject/Help/*.hhc 115 | DocProject/Help/*.hhk 116 | DocProject/Help/*.hhp 117 | DocProject/Help/Html2 118 | DocProject/Help/html 119 | 120 | # Click-Once directory 121 | publish/ 122 | 123 | # Publish Web Output 124 | *.[Pp]ublish.xml 125 | *.azurePubxml 126 | ## TODO: Comment the next line if you want to checkin your 127 | ## web deploy settings but do note that will include unencrypted 128 | ## passwords 129 | #*.pubxml 130 | 131 | # NuGet Packages Directory 132 | src/packages/* 133 | ## TODO: If the tool you use requires repositories.config 134 | ## uncomment the next line 135 | #!packages/repositories.config 136 | 137 | # Enable "build/" folder in the NuGet Packages folder since 138 | # NuGet packages use it for MSBuild targets. 139 | # This line needs to be after the ignore of the build folder 140 | # (and the packages folder if the line above has been uncommented) 141 | !packages/build/ 142 | 143 | # Windows Azure Build Output 144 | csx/ 145 | *.build.csdef 146 | 147 | # Windows Store app package directory 148 | AppPackages/ 149 | 150 | # Others 151 | sql/ 152 | *.Cache 153 | ClientBin/ 154 | [Ss]tyle[Cc]op.* 155 | ~$* 156 | *~ 157 | *.dbmdl 158 | *.dbproj.schemaview 159 | *.pfx 160 | *.publishsettings 161 | node_modules/ 162 | bower_components/ 163 | 164 | # RIA/Silverlight projects 165 | Generated_Code/ 166 | 167 | # Backup & report files from converting an old project file 168 | # to a newer Visual Studio version. Backup files are not needed, 169 | # because we have git ;-) 170 | _UpgradeReport_Files/ 171 | Backup*/ 172 | UpgradeLog*.XML 173 | UpgradeLog*.htm 174 | 175 | # SQL Server files 176 | *.mdf 177 | *.ldf 178 | 179 | # Business Intelligence projects 180 | *.rdl.data 181 | *.bim.layout 182 | *.bim_*.settings 183 | 184 | # Microsoft Fakes 185 | FakesAssemblies/ 186 | 187 | # LightSwitch generated files 188 | GeneratedArtifacts/ 189 | _Pvt_Extensions/ 190 | ModelManifest.xml -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006-2009, Salvatore Sanfilippo 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | * 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. 8 | * Neither the name of Smaz nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 9 | 10 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS 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 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 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. 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SmazSharp - C# Compression For Very Small Strings 2 | ------------------------------------------------- 3 | 4 | *based on [SMAZ](https://github.com/antirez/smaz) - C implementation by Salvatore Sanfilippo* 5 | 6 | > #### [on NuGet](https://nuget.org/packages/SmazSharp/) 7 | > ```PowerShell 8 | > Install-Package SmazSharp 9 | > ``` 10 | 11 | SmazSharp is a simple compression library suitable for compressing very short 12 | strings. General purpose compression libraries will build the state needed 13 | for compressing data dynamically, in order to be able to compress every kind 14 | of data. This is a very good idea, but not for a specific problem: compressing 15 | small strings will not work. 16 | 17 | SmazSharp instead is not good for compressing general purpose data, but can compress 18 | text by 40-50% in the average case (works better with English), and is able to 19 | perform a bit of compression for HTML and urls as well. The important point is 20 | that Smaz is able to compress even strings of two or three bytes! 21 | 22 | For example the string "the" is compressed into a single byte. 23 | 24 | To compare this with other libraries, think that like zlib will usually not be able to compress text shorter than 100 bytes. 25 | 26 | COMPRESSION EXAMPLES 27 | -------------------- 28 | 29 | - 'This is a small string' compressed by 50% 30 | - 'foobar' compressed by 34% 31 | - 'the end' compressed by 58% 32 | - 'not-a-g00d-Exampl333' enlarged by 15% 33 | - 'Smaz is a simple compression library' compressed by 39% 34 | - 'Nothing is more difficult, and therefore more precious, than to be able to decide' compressed by 49% 35 | - 'this is an example of what works very well with smaz' compressed by 49% 36 | - '1000 numbers 2000 will 10 20 30 compress very little' compressed by 10% 37 | 38 | In general, lowercase English will work very well. It will degrade with a lot 39 | of numbers inside the strings. Other languages are compressed pretty well too, 40 | the following is Italian, not very similar to English but still compressible 41 | by SmazSharp: 42 | 43 | - 'Nel mezzo del cammin di nostra vita, mi ritrovai in una selva oscura' compressed by 33% 44 | - 'Mi illumino di immenso' compressed by 37% 45 | - 'L'autore di questa libreria vive in Sicilia' compressed by 28% 46 | 47 | It can compress URLS pretty well: 48 | 49 | - 'http://google.com' compressed by 59% 50 | - 'http://programming.reddit.com' compressed by 52% 51 | - 'http://github.com/antirez/smaz/tree/master' compressed by 46% 52 | 53 | USAGE 54 | ----- 55 | 56 | The library consists of two primary functions: 57 | 58 | ```C# 59 | byte[] SmazSharp.Smaz.Compress(string Input); 60 | ``` 61 | 62 | Compress the `Input` string and return the compressed data in a byte array. 63 | 64 | ```C# 65 | string SmazSharp.Smaz.Decompress(byte[] Input); 66 | ``` 67 | 68 | Decompress the `Input` byte array and return the decompressed data as a string. 69 | 70 | 71 | CREDITS 72 | ------- 73 | 74 | SmazSharp is based on [SMAZ](https://github.com/antirez/smaz), written by Salvatore Sanfilippo which was released under the BSD license. Check the COPYING file for more information. 75 | -------------------------------------------------------------------------------- /src/SmazSharp.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SmazSharp 5 | 0.1.0.0 6 | SmazSharp 7 | Salvatore Sanfilippo, Gary Sharp 8 | Salvatore Sanfilippo, Gary Sharp 9 | https://github.com/garysharp/SmazSharp/blob/master/COPYING 10 | https://github.com/garysharp/SmazSharp 11 | false 12 | Compression for very small strings 13 | Initial port of Smaz to C#. 14 | Copyright 2006-2009, Salvatore Sanfilippo 15 | compression small strings 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/SmazSharp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.22823.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmazSharp", "SmazSharp\SmazSharp.csproj", "{9ABB67FC-CE56-40B1-8F4B-48F59C89ADFD}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmazSharpTests", "SmazSharpTests\SmazSharpTests.csproj", "{09132478-D059-49C8-884B-19D99AC5EA9F}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmazSharp-20", "SmazSharp\SmazSharp-20.csproj", "{70E58D0F-F7A4-456A-8443-6365C998E3FF}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmazSharp-30", "SmazSharp\SmazSharp-30.csproj", "{26FF4BF0-B1B8-4A5D-AE59-2998E8F7E1C9}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmazSharp-35", "SmazSharp\SmazSharp-35.csproj", "{5F5A94E0-3617-4E5D-A1EA-5066F3A46C46}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmazSharp-40", "SmazSharp\SmazSharp-40.csproj", "{28414768-3F35-4D00-8E5F-077D99974F1A}" 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|Any CPU = Debug|Any CPU 21 | Release|Any CPU = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {9ABB67FC-CE56-40B1-8F4B-48F59C89ADFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {9ABB67FC-CE56-40B1-8F4B-48F59C89ADFD}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {9ABB67FC-CE56-40B1-8F4B-48F59C89ADFD}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {9ABB67FC-CE56-40B1-8F4B-48F59C89ADFD}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {09132478-D059-49C8-884B-19D99AC5EA9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {09132478-D059-49C8-884B-19D99AC5EA9F}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {09132478-D059-49C8-884B-19D99AC5EA9F}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {09132478-D059-49C8-884B-19D99AC5EA9F}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {70E58D0F-F7A4-456A-8443-6365C998E3FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {70E58D0F-F7A4-456A-8443-6365C998E3FF}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {70E58D0F-F7A4-456A-8443-6365C998E3FF}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {70E58D0F-F7A4-456A-8443-6365C998E3FF}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {26FF4BF0-B1B8-4A5D-AE59-2998E8F7E1C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {26FF4BF0-B1B8-4A5D-AE59-2998E8F7E1C9}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {26FF4BF0-B1B8-4A5D-AE59-2998E8F7E1C9}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {26FF4BF0-B1B8-4A5D-AE59-2998E8F7E1C9}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {5F5A94E0-3617-4E5D-A1EA-5066F3A46C46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {5F5A94E0-3617-4E5D-A1EA-5066F3A46C46}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {5F5A94E0-3617-4E5D-A1EA-5066F3A46C46}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {5F5A94E0-3617-4E5D-A1EA-5066F3A46C46}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {28414768-3F35-4D00-8E5F-077D99974F1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {28414768-3F35-4D00-8E5F-077D99974F1A}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {28414768-3F35-4D00-8E5F-077D99974F1A}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {28414768-3F35-4D00-8E5F-077D99974F1A}.Release|Any CPU.Build.0 = Release|Any CPU 48 | EndGlobalSection 49 | GlobalSection(SolutionProperties) = preSolution 50 | HideSolutionNode = FALSE 51 | EndGlobalSection 52 | EndGlobal 53 | -------------------------------------------------------------------------------- /src/SmazSharp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SmazSharp")] 9 | [assembly: AssemblyDescription("Compression for very small strings")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SmazSharp")] 13 | [assembly: AssemblyCopyright("Copyright © 2006-2009, Salvatore Sanfilippo")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("9abb67fc-ce56-40b1-8f4b-48f59c89adfd")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("0.1.0.0")] 36 | [assembly: AssemblyFileVersion("0.1.0.0")] 37 | -------------------------------------------------------------------------------- /src/SmazSharp/Smaz.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | 5 | namespace SmazSharp 6 | { 7 | /// 8 | /// Compression for very small strings 9 | /// 10 | public static class Smaz 11 | { 12 | #region Lookup Data 13 | private static readonly byte[][] encoderLookup = { 14 | new byte[] {2, 115, 44, 182}, new byte[] {3, 104, 97, 100, 154, 2, 108, 101, 87}, new byte[] {3, 111, 110, 32, 142}, null, new byte[] {1, 121, 83}, 15 | new byte[] {2, 109, 97, 173, 2, 108, 105, 151}, new byte[] {3, 111, 114, 32, 176}, null, new byte[] {2, 108, 108, 152, 3, 115, 32, 116, 191}, 16 | new byte[] {4, 102, 114, 111, 109, 103, 2, 109, 101, 108}, null, new byte[] {3, 105, 116, 115, 218}, new byte[] {1, 122, 219}, 17 | new byte[] {3, 105, 110, 103, 70}, new byte[] {1, 62, 222}, new byte[] {1, 32, 0, 3, 32, 32, 32, 40, 2, 110, 99, 228}, 18 | new byte[] {2, 110, 100, 61, 3, 32, 111, 110, 202}, new byte[] {2, 110, 101, 139, 3, 104, 97, 116, 190, 3, 114, 101, 32, 113}, null, 19 | new byte[] {2, 110, 103, 84, 3, 104, 101, 114, 122, 4, 104, 97, 118, 101, 198, 3, 115, 32, 111, 149}, null, 20 | new byte[] {3, 105, 111, 110, 107, 3, 115, 32, 97, 172, 2, 108, 121, 234}, new byte[] {3, 104, 105, 115, 76, 3, 32, 105, 110, 78, 3, 32, 98, 101, 170}, 21 | null, new byte[] {3, 32, 102, 111, 213, 3, 32, 111, 102, 32, 3, 32, 104, 97, 201}, null, new byte[] {2, 111, 102, 5}, 22 | new byte[] {3, 32, 99, 111, 161, 2, 110, 111, 183, 3, 32, 109, 97, 248}, null, null, 23 | new byte[] {3, 32, 99, 108, 238, 3, 101, 110, 116, 97, 3, 32, 97, 110, 55}, new byte[] {2, 110, 115, 192, 1, 34, 101}, 24 | new byte[] {3, 110, 32, 116, 143, 2, 110, 116, 80, 3, 115, 44, 32, 133}, new byte[] {2, 112, 101, 208, 3, 32, 119, 101, 233, 2, 111, 109, 147}, 25 | new byte[] {2, 111, 110, 31}, null, new byte[] {2, 121, 32, 71}, new byte[] {3, 32, 119, 97, 185}, new byte[] {3, 32, 114, 101, 209, 2, 111, 114, 42}, 26 | null, new byte[] {2, 61, 34, 169, 2, 111, 116, 223}, new byte[] {3, 102, 111, 114, 68, 2, 111, 117, 91}, new byte[] {3, 32, 116, 111, 82}, 27 | new byte[] {3, 32, 116, 104, 13}, new byte[] {3, 32, 105, 116, 246}, new byte[] {3, 98, 117, 116, 177, 2, 114, 97, 130, 3, 32, 119, 105, 243, 2, 60, 47, 241}, 28 | new byte[] {3, 32, 119, 104, 159}, new byte[] {2, 32, 32, 52}, new byte[] {3, 110, 100, 32, 63}, new byte[] {2, 114, 101, 33}, null, 29 | new byte[] {3, 110, 103, 32, 99}, null, new byte[] {3, 108, 121, 32, 199, 3, 97, 115, 115, 211, 1, 97, 4, 2, 114, 105, 114}, null, null, null, 30 | new byte[] {2, 115, 101, 95}, new byte[] {3, 111, 102, 32, 34}, new byte[] {3, 100, 105, 118, 244, 2, 114, 111, 115, 3, 101, 114, 101, 160}, null, 31 | new byte[] {2, 116, 97, 200, 1, 98, 90, 2, 115, 105, 212}, null, new byte[] {3, 97, 110, 100, 7, 2, 114, 115, 221}, new byte[] {2, 114, 116, 242}, 32 | new byte[] {2, 116, 101, 69}, new byte[] {3, 97, 116, 105, 206}, new byte[] {2, 115, 111, 179}, new byte[] {2, 116, 104, 17}, 33 | new byte[] {2, 116, 105, 74, 1, 99, 28, 3, 97, 108, 108, 112}, new byte[] {3, 97, 116, 101, 229}, new byte[] {2, 115, 115, 166}, new byte[] {2, 115, 116, 77}, 34 | null, new byte[] {2, 62, 60, 230}, new byte[] {2, 116, 111, 20}, new byte[] {3, 97, 114, 101, 119}, new byte[] {1, 100, 24}, new byte[] {2, 116, 114, 195}, 35 | null, new byte[] {1, 10, 49, 3, 32, 97, 32, 146}, new byte[] {3, 102, 32, 116, 118, 2, 118, 101, 111}, new byte[] {2, 117, 110, 224}, null, 36 | new byte[] {3, 101, 32, 111, 162}, new byte[] {2, 97, 32, 163, 2, 119, 97, 214, 1, 101, 2}, new byte[] {2, 117, 114, 150, 3, 101, 32, 97, 188}, 37 | new byte[] {2, 117, 115, 164, 3, 10, 13, 10, 167}, new byte[] {2, 117, 116, 196, 3, 101, 32, 99, 251}, new byte[] {2, 119, 101, 145}, null, null, 38 | new byte[] {2, 119, 104, 194}, new byte[] {1, 102, 44}, null, null, null, new byte[] {3, 100, 32, 116, 134}, null, null, new byte[] {3, 116, 104, 32, 227}, 39 | new byte[] {1, 103, 59}, null, null, new byte[] {1, 13, 57, 3, 101, 32, 115, 181}, new byte[] {3, 101, 32, 116, 156}, null, new byte[] {3, 116, 111, 32, 89}, 40 | new byte[] {3, 101, 13, 10, 158}, new byte[] {2, 100, 32, 30, 1, 104, 18}, null, new byte[] {1, 44, 81}, new byte[] {2, 32, 97, 25}, 41 | new byte[] {2, 32, 98, 94}, new byte[] {2, 13, 10, 21, 2, 32, 99, 73}, new byte[] {2, 32, 100, 165}, new byte[] {2, 32, 101, 171}, 42 | new byte[] {2, 32, 102, 104, 1, 105, 8, 2, 101, 32, 11}, null, new byte[] {2, 32, 104, 85, 1, 45, 204}, new byte[] {2, 32, 105, 56}, null, null, 43 | new byte[] {2, 32, 108, 205}, new byte[] {2, 32, 109, 123}, new byte[] {2, 102, 32, 58, 2, 32, 110, 236}, new byte[] {2, 32, 111, 29}, 44 | new byte[] {2, 32, 112, 125, 1, 46, 110, 3, 13, 10, 13, 168}, null, new byte[] {2, 32, 114, 189}, new byte[] {2, 32, 115, 62}, new byte[] {2, 32, 116, 14}, 45 | null, new byte[] {2, 103, 32, 157, 5, 119, 104, 105, 99, 104, 43, 3, 119, 104, 105, 247}, new byte[] {2, 32, 119, 53}, new byte[] {1, 47, 197}, 46 | new byte[] {3, 97, 115, 32, 140}, new byte[] {3, 97, 116, 32, 135}, null, new byte[] {3, 119, 104, 111, 217}, null, new byte[] {1, 108, 22, 2, 104, 32, 138}, 47 | null, new byte[] {2, 44, 32, 36}, null, new byte[] {4, 119, 105, 116, 104, 86}, null, null, null, new byte[] {1, 109, 45}, null, null, 48 | new byte[] {2, 97, 99, 239}, new byte[] {2, 97, 100, 232}, new byte[] {3, 84, 104, 101, 72}, null, null, new byte[] {4, 116, 104, 105, 115, 155, 1, 110, 9}, 49 | null, new byte[] {2, 46, 32, 121}, null, new byte[] {2, 97, 108, 88, 3, 101, 44, 32, 245}, new byte[] {3, 116, 105, 111, 141, 2, 98, 101, 92}, 50 | new byte[] {2, 97, 110, 26, 3, 118, 101, 114, 231}, null, new byte[] {4, 116, 104, 97, 116, 48, 3, 116, 104, 97, 203, 1, 111, 6}, 51 | new byte[] {3, 119, 97, 115, 50}, new byte[] {2, 97, 114, 79}, new byte[] {2, 97, 115, 46}, 52 | new byte[] {2, 97, 116, 39, 3, 116, 104, 101, 1, 4, 116, 104, 101, 121, 128, 5, 116, 104, 101, 114, 101, 210, 5, 116, 104, 101, 105, 114, 100}, 53 | new byte[] {2, 99, 101, 136}, new byte[] {4, 119, 101, 114, 101, 93}, null, new byte[] {2, 99, 104, 153, 2, 108, 32, 180, 1, 112, 60}, null, null, 54 | new byte[] {3, 111, 110, 101, 174}, null, new byte[] {3, 104, 101, 32, 19, 2, 100, 101, 106}, new byte[] {3, 116, 101, 114, 184}, 55 | new byte[] {2, 99, 111, 117}, null, new byte[] {2, 98, 121, 127, 2, 100, 105, 129, 2, 101, 97, 120}, null, new byte[] {2, 101, 99, 215}, 56 | new byte[] {2, 101, 100, 66}, new byte[] {2, 101, 101, 235}, null, null, new byte[] {1, 114, 12, 2, 110, 32, 41}, null, null, null, 57 | new byte[] {2, 101, 108, 178}, null, new byte[] {3, 105, 110, 32, 105, 2, 101, 110, 51}, null, new byte[] {2, 111, 32, 96, 1, 115, 10}, null, 58 | new byte[] {2, 101, 114, 27}, new byte[] {3, 105, 115, 32, 116, 2, 101, 115, 54}, null, new byte[] {2, 103, 101, 249}, new byte[] {4, 46, 99, 111, 109, 253}, 59 | new byte[] {2, 102, 111, 220, 3, 111, 117, 114, 216}, new byte[] {3, 99, 104, 32, 193, 1, 116, 3}, new byte[] {2, 104, 97, 98}, null, 60 | new byte[] {3, 109, 101, 110, 252}, null, new byte[] {2, 104, 101, 16}, null, null, new byte[] {1, 117, 38}, new byte[] {2, 104, 105, 102}, null, 61 | new byte[] {3, 110, 111, 116, 132, 2, 105, 99, 131}, new byte[] {3, 101, 100, 32, 64, 2, 105, 100, 237}, null, null, new byte[] {2, 104, 111, 187}, 62 | new byte[] {2, 114, 32, 75, 1, 118, 109}, null, null, null, new byte[] {3, 116, 32, 116, 175, 2, 105, 108, 240}, new byte[] {2, 105, 109, 226}, 63 | new byte[] {3, 101, 110, 32, 207, 2, 105, 110, 15}, new byte[] {2, 105, 111, 144}, new byte[] {2, 115, 32, 23, 1, 119, 65}, null, 64 | new byte[] {3, 101, 114, 32, 124}, new byte[] {3, 101, 115, 32, 126, 2, 105, 115, 37}, new byte[] {2, 105, 116, 47}, null, new byte[] {2, 105, 118, 186}, 65 | null, new byte[] {2, 116, 32, 35, 7, 104, 116, 116, 112, 58, 47, 47, 67, 1, 120, 250}, new byte[] {2, 108, 97, 137}, new byte[] {1, 60, 225}, 66 | new byte[] {3, 44, 32, 97, 148} 67 | }; 68 | 69 | /* Decode List 70 | 000 = 051 = en 102 = hi 153 = ch 204 = - 71 | 001 = the 052 = 103 = from 154 = had 205 = l 72 | 002 = e 053 = w 104 = f 155 = this 206 = ati 73 | 003 = t 054 = es 105 = in 156 = et 207 = en 74 | 004 = a 055 = an 106 = de 157 = g 208 = pe 75 | 005 = of 056 = i 107 = ion 158 = e 209 = re 76 | 006 = o 057 = 108 = me 159 = wh 210 = there 77 | 007 = and 058 = f 109 = v 160 = ere 211 = ass 78 | 008 = i 059 = g 110 = . 161 = co 212 = si 79 | 009 = n 060 = p 111 = ve 162 = eo 213 = fo 80 | 010 = s 061 = nd 112 = all 163 = a 214 = wa 81 | 011 = e 062 = s 113 = re 164 = us 215 = ec 82 | 012 = r 063 = nd 114 = ri 165 = d 216 = our 83 | 013 = th 064 = ed 115 = ro 166 = ss 217 = who 84 | 014 = t 065 = w 116 = is 167 = 218 = its 85 | 015 = in 066 = ed 117 = co 168 = 219 = z 86 | 016 = he 067 = http:// 118 = ft 169 = =" 220 = fo 87 | 017 = th 068 = for 119 = are 170 = be 221 = rs 88 | 018 = h 069 = te 120 = ea 171 = e 222 = > 89 | 019 = he 070 = ing 121 = . 172 = sa 223 = ot 90 | 020 = to 071 = y 122 = her 173 = ma 224 = un 91 | 021 = 072 = The 123 = m 174 = one 225 = < 92 | 022 = l 073 = c 124 = er 175 = tt 226 = im 93 | 023 = s 074 = ti 125 = p 176 = or 227 = th 94 | 024 = d 075 = r 126 = es 177 = but 228 = nc 95 | 025 = a 076 = his 127 = by 178 = el 229 = ate 96 | 026 = an 077 = st 128 = they 179 = so 230 = >< 97 | 027 = er 078 = in 129 = di 180 = l 231 = ver 98 | 028 = c 079 = ar 130 = ra 181 = es 232 = ad 99 | 029 = o 080 = nt 131 = ic 182 = s, 233 = we 100 | 030 = d 081 = , 132 = not 183 = no 234 = ly 101 | 031 = on 082 = to 133 = s, 184 = ter 235 = ee 102 | 032 = of 083 = y 134 = dt 185 = wa 236 = n 103 | 033 = re 084 = ng 135 = at 186 = iv 237 = id 104 | 034 = of 085 = h 136 = ce 187 = ho 238 = cl 105 | 035 = t 086 = with 137 = la 188 = ea 239 = ac 106 | 036 = , 087 = le 138 = h 189 = r 240 = il 107 | 037 = is 088 = al 139 = ne 190 = hat 241 = 140 = as 191 = st 242 = rt 109 | 039 = at 090 = b 141 = tio 192 = ns 243 = wi 110 | 040 = 091 = ou 142 = on 193 = ch 244 = div 111 | 041 = n 092 = be 143 = nt 194 = wh 245 = e, 112 | 042 = or 093 = were 144 = io 195 = tr 246 = it 113 | 043 = which 094 = b 145 = we 196 = ut 247 = whi 114 | 044 = f 095 = se 146 = a 197 = / 248 = ma 115 | 045 = m 096 = o 147 = om 198 = have 249 = ge 116 | 046 = as 097 = ent 148 = ,a 199 = ly 250 = x 117 | 047 = it 098 = ha 149 = so 200 = ta 251 = ec 118 | 048 = that 099 = ng 150 = ur 201 = ha 252 = men 119 | 049 = 100 = their 151 = li 202 = on 253 = .com 120 | 050 = was 101 = " 152 = ll 203 = tha 121 | */ 122 | private static readonly byte[][] decoderLookup = 123 | { 124 | new byte[] {32}, new byte[] {116, 104, 101}, new byte[] {101}, new byte[] {116}, new byte[] {97}, new byte[] {111, 102}, new byte[] {111}, 125 | new byte[] {97, 110, 100}, new byte[] {105}, new byte[] {110}, new byte[] {115}, new byte[] {101, 32}, new byte[] {114}, 126 | new byte[] {32, 116, 104}, new byte[] {32, 116}, new byte[] {105, 110}, new byte[] {104, 101}, new byte[] {116, 104}, new byte[] {104}, 127 | new byte[] {104, 101, 32}, new byte[] {116, 111}, new byte[] {13, 10}, new byte[] {108}, new byte[] {115, 32}, new byte[] {100}, 128 | new byte[] {32, 97}, new byte[] {97, 110}, new byte[] {101, 114}, new byte[] {99}, new byte[] {32, 111}, new byte[] {100, 32}, 129 | new byte[] {111, 110}, new byte[] {32, 111, 102}, new byte[] {114, 101}, new byte[] {111, 102, 32}, new byte[] {116, 32}, 130 | new byte[] {44, 32}, new byte[] {105, 115}, new byte[] {117}, new byte[] {97, 116}, new byte[] {32, 32, 32}, new byte[] {110, 32}, 131 | new byte[] {111, 114}, new byte[] {119, 104, 105, 99, 104}, new byte[] {102}, new byte[] {109}, new byte[] {97, 115}, 132 | new byte[] {105, 116}, new byte[] {116, 104, 97, 116}, new byte[] {10}, new byte[] {119, 97, 115}, new byte[] {101, 110}, 133 | new byte[] {32, 32}, new byte[] {32, 119}, new byte[] {101, 115}, new byte[] {32, 97, 110}, new byte[] {32, 105}, new byte[] {13}, 134 | new byte[] {102, 32}, new byte[] {103}, new byte[] {112}, new byte[] {110, 100}, new byte[] {32, 115}, new byte[] {110, 100, 32}, 135 | new byte[] {101, 100, 32}, new byte[] {119}, new byte[] {101, 100}, new byte[] {104, 116, 116, 112, 58, 47, 47}, new byte[] {102, 111, 114}, 136 | new byte[] {116, 101}, new byte[] {105, 110, 103}, new byte[] {121, 32}, new byte[] {84, 104, 101}, new byte[] {32, 99}, 137 | new byte[] {116, 105}, new byte[] {114, 32}, new byte[] {104, 105, 115}, new byte[] {115, 116}, new byte[] {32, 105, 110}, 138 | new byte[] {97, 114}, new byte[] {110, 116}, new byte[] {44}, new byte[] {32, 116, 111}, new byte[] {121}, new byte[] {110, 103}, 139 | new byte[] {32, 104}, new byte[] {119, 105, 116, 104}, new byte[] {108, 101}, new byte[] {97, 108}, new byte[] {116, 111, 32}, 140 | new byte[] {98}, new byte[] {111, 117}, new byte[] {98, 101}, new byte[] {119, 101, 114, 101}, new byte[] {32, 98}, 141 | new byte[] {115, 101}, new byte[] {111, 32}, new byte[] {101, 110, 116}, new byte[] {104, 97}, new byte[] {110, 103, 32}, 142 | new byte[] {116, 104, 101, 105, 114}, new byte[] {34}, new byte[] {104, 105}, new byte[] {102, 114, 111, 109}, new byte[] {32, 102}, 143 | new byte[] {105, 110, 32}, new byte[] {100, 101}, new byte[] {105, 111, 110}, new byte[] {109, 101}, new byte[] {118}, new byte[] {46}, 144 | new byte[] {118, 101}, new byte[] {97, 108, 108}, new byte[] {114, 101, 32}, new byte[] {114, 105}, new byte[] {114, 111}, 145 | new byte[] {105, 115, 32}, new byte[] {99, 111}, new byte[] {102, 32, 116}, new byte[] {97, 114, 101}, new byte[] {101, 97}, 146 | new byte[] {46, 32}, new byte[] {104, 101, 114}, new byte[] {32, 109}, new byte[] {101, 114, 32}, new byte[] {32, 112}, 147 | new byte[] {101, 115, 32}, new byte[] {98, 121}, new byte[] {116, 104, 101, 121}, new byte[] {100, 105}, new byte[] {114, 97}, 148 | new byte[] {105, 99}, new byte[] {110, 111, 116}, new byte[] {115, 44, 32}, new byte[] {100, 32, 116}, new byte[] {97, 116, 32}, 149 | new byte[] {99, 101}, new byte[] {108, 97}, new byte[] {104, 32}, new byte[] {110, 101}, new byte[] {97, 115, 32}, new byte[] {116, 105, 111}, 150 | new byte[] {111, 110, 32}, new byte[] {110, 32, 116}, new byte[] {105, 111}, new byte[] {119, 101}, new byte[] {32, 97, 32}, 151 | new byte[] {111, 109}, new byte[] {44, 32, 97}, new byte[] {115, 32, 111}, new byte[] {117, 114}, new byte[] {108, 105}, 152 | new byte[] {108, 108}, new byte[] {99, 104}, new byte[] {104, 97, 100}, new byte[] {116, 104, 105, 115}, new byte[] {101, 32, 116}, 153 | new byte[] {103, 32}, new byte[] {101, 13, 10}, new byte[] {32, 119, 104}, new byte[] {101, 114, 101}, new byte[] {32, 99, 111}, 154 | new byte[] {101, 32, 111}, new byte[] {97, 32}, new byte[] {117, 115}, new byte[] {32, 100}, new byte[] {115, 115}, new byte[] {10, 13, 10}, 155 | new byte[] {13, 10, 13}, new byte[] {61, 34}, new byte[] {32, 98, 101}, new byte[] {32, 101}, new byte[] {115, 32, 97}, new byte[] {109, 97}, 156 | new byte[] {111, 110, 101}, new byte[] {116, 32, 116}, new byte[] {111, 114, 32}, new byte[] {98, 117, 116}, new byte[] {101, 108}, 157 | new byte[] {115, 111}, new byte[] {108, 32}, new byte[] {101, 32, 115}, new byte[] {115, 44}, new byte[] {110, 111}, new byte[] {116, 101, 114}, 158 | new byte[] {32, 119, 97}, new byte[] {105, 118}, new byte[] {104, 111}, new byte[] {101, 32, 97}, new byte[] {32, 114}, new byte[] {104, 97, 116}, 159 | new byte[] {115, 32, 116}, new byte[] {110, 115}, new byte[] {99, 104, 32}, new byte[] {119, 104}, new byte[] {116, 114}, new byte[] {117, 116}, 160 | new byte[] {47}, new byte[] {104, 97, 118, 101}, new byte[] {108, 121, 32}, new byte[] {116, 97}, new byte[] {32, 104, 97}, new byte[] {32, 111, 110}, 161 | new byte[] {116, 104, 97}, new byte[] {45}, new byte[] {32, 108}, new byte[] {97, 116, 105}, new byte[] {101, 110, 32}, new byte[] {112, 101}, 162 | new byte[] {32, 114, 101}, new byte[] {116, 104, 101, 114, 101}, new byte[] {97, 115, 115}, new byte[] {115, 105}, new byte[] {32, 102, 111}, 163 | new byte[] {119, 97}, new byte[] {101, 99}, new byte[] {111, 117, 114}, new byte[] {119, 104, 111}, new byte[] {105, 116, 115}, new byte[] {122}, 164 | new byte[] {102, 111}, new byte[] {114, 115}, new byte[] {62}, new byte[] {111, 116}, new byte[] {117, 110}, new byte[] {60}, 165 | new byte[] {105, 109}, new byte[] {116, 104, 32}, new byte[] {110, 99}, new byte[] {97, 116, 101}, new byte[] {62, 60}, 166 | new byte[] {118, 101, 114}, new byte[] {97, 100}, new byte[] {32, 119, 101}, new byte[] {108, 121}, new byte[] {101, 101}, new byte[] {32, 110}, 167 | new byte[] {105, 100}, new byte[] {32, 99, 108}, new byte[] {97, 99}, new byte[] {105, 108}, new byte[] {60, 47}, new byte[] {114, 116}, 168 | new byte[] {32, 119, 105}, new byte[] {100, 105, 118}, new byte[] {101, 44, 32}, new byte[] {32, 105, 116}, new byte[] {119, 104, 105}, 169 | new byte[] {32, 109, 97}, new byte[] {103, 101}, new byte[] {120}, new byte[] {101, 32, 99}, new byte[] {109, 101, 110}, new byte[] {46, 99, 111, 109} 170 | }; 171 | #endregion 172 | 173 | /// 174 | /// Compresses a byte array using Smaz encoding 175 | /// 176 | /// ASCII encoded Data to be compressed 177 | /// Compressed data as a byte array 178 | public static byte[] Compress(byte[] Input) 179 | { 180 | // Output buffer 181 | byte[] buf = new byte[Input.Length]; 182 | int bufPos = 0; 183 | 184 | int inLen = Input.Length; 185 | 186 | int inPos = 0, 187 | verbPos = 0; 188 | byte verbLen = 0; 189 | 190 | int h1, h2, h3 = 0; 191 | 192 | // Loop through each input character 193 | while (inLen > 0) 194 | { 195 | int j = 7; 196 | bool found = false; 197 | 198 | // Determine encoder lookup index 199 | h1 = h2 = Input[inPos] << 3; 200 | if (inLen > 1) 201 | { 202 | h2 += Input[inPos + 1]; 203 | } 204 | if (inLen > 2) 205 | { 206 | h3 = h2 ^ Input[inPos + 2]; 207 | } 208 | if (j > inLen) 209 | { 210 | j = inLen; 211 | } 212 | 213 | // Search for encoder words (from largest (7) to smallest (1)) 214 | for (; j > 0; j--) 215 | { 216 | // Fetch relevant encoder slot (based on word length (j) and input data (h1, h2, h3)) 217 | byte[] slot; 218 | switch (j) 219 | { 220 | case 1: 221 | slot = encoderLookup[h1 % 241]; 222 | break; 223 | case 2: 224 | slot = encoderLookup[h2 % 241]; 225 | break; 226 | default: 227 | slot = encoderLookup[h3 % 241]; 228 | break; 229 | } 230 | 231 | // Skip if slot is null 232 | if (slot != null) 233 | { 234 | // Iterate through all slot word entries 235 | var slotPos = 0; 236 | while (slot.Length > slotPos) 237 | { 238 | // Check slot word length's match 239 | if (slot[slotPos] == j) 240 | { 241 | // Byte-wise compare slot word to input 242 | found = true; 243 | for (int i = 0; i < j; i++) 244 | { 245 | if (Input[inPos + i] != slot[slotPos + i + 1]) 246 | { 247 | // Doesn't match, break and try next slot word 248 | found = false; 249 | break; 250 | } 251 | } 252 | 253 | if (found) 254 | { 255 | // Check if output buffer resize is required 256 | if (bufPos + verbLen + 3 > buf.Length) 257 | { 258 | Array.Resize(ref buf, buf.Length * 2); 259 | } 260 | 261 | // Write verbatim data (where no encoder word is available) 262 | if (verbLen > 0) 263 | { 264 | if (verbLen == 1) 265 | { 266 | // Single byte, prefix with [254] 267 | buf[bufPos++] = 254; 268 | buf[bufPos++] = Input[verbPos]; 269 | } 270 | else 271 | { 272 | // Multiple bytes, prefix with [255] and [length] 273 | buf[bufPos++] = 255; 274 | buf[bufPos++] = verbLen; 275 | Array.Copy(Input, Input.Length - inLen - verbLen, buf, bufPos, verbLen); 276 | bufPos += verbLen; 277 | } 278 | } 279 | 280 | // Write encoded word index 281 | buf[bufPos++] = slot[slot[slotPos] + slotPos + 1]; 282 | 283 | // Move input position forward (by the length of the encoded word) 284 | inLen -= j; 285 | inPos += j; 286 | 287 | // Reset verbatim position (to the current input position) 288 | verbPos = inPos; 289 | verbLen = 0; 290 | 291 | // Found word, so break slot loop, and continue at new input position 292 | break; 293 | } 294 | } 295 | 296 | // Try next word in slot 297 | slotPos += slot[slotPos] + 2; 298 | } 299 | 300 | if (found) 301 | { 302 | // Word found, so break word-length loop, and continue at new input position 303 | break; 304 | } 305 | } 306 | } 307 | 308 | if (!found) 309 | { 310 | // No encoder word was found, so increase verbatim length, 311 | // and continue at the new input position 312 | verbLen++; 313 | inLen--; 314 | inPos++; 315 | } 316 | 317 | // If verbatim length is maximum (255), or if the end is reached 318 | // then flush the verbatim data to the output buffer 319 | if (verbLen == 255 || (verbLen > 0 && inLen == 0)) 320 | { 321 | // Check if output buffer resize is required 322 | if (bufPos + verbLen + 2 > buf.Length) 323 | { 324 | Array.Resize(ref buf, buf.Length * 2); 325 | } 326 | 327 | // Write verbatim data to the output buffer 328 | if (verbLen == 1) 329 | { 330 | // Single byte, prefix with [254] 331 | buf[bufPos++] = 254; 332 | buf[bufPos++] = Input[verbPos]; 333 | } 334 | else 335 | { 336 | // Multiple bytes, prefix with [255] and [length] 337 | buf[bufPos++] = 255; 338 | buf[bufPos++] = verbLen; 339 | Array.Copy(Input, Input.Length - inLen - verbLen, buf, bufPos, verbLen); 340 | bufPos += verbLen; 341 | } 342 | 343 | // Reset verbatim position (to the current input position) 344 | verbPos = inPos; 345 | verbLen = 0; 346 | } 347 | } 348 | 349 | // Size output buffer to final size 350 | if (bufPos != buf.Length) 351 | { 352 | Array.Resize(ref buf, bufPos); 353 | } 354 | 355 | // Return output buffer 356 | return buf; 357 | } 358 | 359 | /// 360 | /// Compresses an ASCII string to a Smaz encoded byte array 361 | /// 362 | /// String to compress 363 | /// Compressed data as a byte array 364 | public static byte[] Compress(string Input) 365 | { 366 | return Compress(Encoding.ASCII.GetBytes(Input)); 367 | } 368 | 369 | /// 370 | /// Decompresses a Smaz encoded byte array and returns the original string 371 | /// 372 | /// Smaz encoded byte array 373 | /// Decompressed string 374 | public static string Decompress(byte[] Input) 375 | { 376 | // Instantiate an output buffer 377 | using (MemoryStream output = new MemoryStream(Input.Length * 3)) 378 | { 379 | for (int i = 0; i < Input.Length; i++) 380 | { 381 | switch (Input[i]) 382 | { 383 | case 254: 384 | // Verbatim Byte 385 | output.WriteByte(Input[i + 1]); 386 | i++; 387 | break; 388 | case 255: 389 | // Verbatim Bytes 390 | output.Write(Input, i + 2, Input[i + 1]); 391 | i += Input[i + 1] + 1; 392 | break; 393 | default: 394 | // Write Encoded Byte 395 | var w = decoderLookup[Input[i]]; 396 | output.Write(w, 0, w.Length); 397 | break; 398 | } 399 | } 400 | return Encoding.ASCII.GetString(output.ToArray()); 401 | } 402 | } 403 | } 404 | } -------------------------------------------------------------------------------- /src/SmazSharp/SmazSharp-20.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {70E58D0F-F7A4-456A-8443-6365C998E3FF} 8 | Library 9 | Properties 10 | SmazSharp 11 | SmazSharp 12 | v2.0 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug-20\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release-20\ 29 | TRACE 30 | prompt 31 | 4 32 | bin\Release-20\SmazSharp.xml 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 49 | -------------------------------------------------------------------------------- /src/SmazSharp/SmazSharp-30.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {26FF4BF0-B1B8-4A5D-AE59-2998E8F7E1C9} 8 | Library 9 | Properties 10 | SmazSharp 11 | SmazSharp 12 | v3.0 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug-30\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release-30\ 29 | TRACE 30 | prompt 31 | 4 32 | bin\Release-30\SmazSharp.xml 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 49 | -------------------------------------------------------------------------------- /src/SmazSharp/SmazSharp-35.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {5F5A94E0-3617-4E5D-A1EA-5066F3A46C46} 8 | Library 9 | Properties 10 | SmazSharp 11 | SmazSharp 12 | v3.5 13 | 512 14 | Client 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug-35\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release-35\ 29 | TRACE 30 | prompt 31 | 4 32 | bin\Release-35\SmazSharp.xml 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 49 | -------------------------------------------------------------------------------- /src/SmazSharp/SmazSharp-40.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {28414768-3F35-4D00-8E5F-077D99974F1A} 8 | Library 9 | Properties 10 | SmazSharp 11 | SmazSharp 12 | v4.0 13 | 512 14 | Client 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug-40\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release-40\ 29 | TRACE 30 | prompt 31 | 4 32 | bin\Release-40\SmazSharp.xml 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 49 | -------------------------------------------------------------------------------- /src/SmazSharp/SmazSharp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {9ABB67FC-CE56-40B1-8F4B-48F59C89ADFD} 8 | Library 9 | Properties 10 | SmazSharp 11 | SmazSharp 12 | v4.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | bin\Release\SmazSharp.xml 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 56 | -------------------------------------------------------------------------------- /src/SmazSharpTests/ComplianceTests.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SmazSharp; 3 | using System; 4 | using System.Text; 5 | using static System.Console; 6 | 7 | namespace SmazSharpTests 8 | { 9 | [TestClass()] 10 | public class ComplianceTests 11 | { 12 | /// 13 | /// Tests SmazSharp Compression (against original C implementation) 14 | /// 15 | [TestMethod(), TestCategory("Compliance")] 16 | public void CompressTest() 17 | { 18 | for (int i = 0; i < Resources.TestStrings.Length; i++) 19 | { 20 | var test = Resources.TestStrings[i]; 21 | var compressedOk = Resources.TestStringsCompressed[i]; 22 | var compressedTest = Smaz.Compress(test); 23 | 24 | // Compare Length 25 | if (compressedOk.Length != compressedTest.Length) 26 | Assert.Fail("Compression failed for: '{0}'", test); 27 | 28 | // Compare Data 29 | for (int c = 0; c < compressedOk.Length; c++) 30 | { 31 | if (compressedOk[c] != compressedTest[c]) 32 | Assert.Fail("Compression failed for: '{0}'", test); 33 | } 34 | } 35 | } 36 | 37 | /// 38 | /// Test SmazSharp Decompression (against original C implementation) 39 | /// 40 | [TestMethod(), TestCategory("Compliance")] 41 | public void DecompressTest() 42 | { 43 | for (int i = 0; i < Resources.TestStringsCompressed.Length; i++) 44 | { 45 | var test = Resources.TestStringsCompressed[i]; 46 | var decompressedOk = Resources.TestStrings[i]; 47 | var decompressedTest = Smaz.Decompress(test); 48 | 49 | Assert.AreEqual(decompressedOk, decompressedTest, "Decompression failed for: '{0}'", decompressedOk); 50 | } 51 | } 52 | 53 | /// 54 | /// Tests that 100 random strings compress/decompress successfully 55 | /// 56 | [TestMethod(), TestCategory("Compliance")] 57 | public void RandomTest() 58 | { 59 | var charset = Resources.TestCharSet; 60 | var test = new StringBuilder(512); 61 | var random = new Random(); 62 | 63 | ForegroundColor = ConsoleColor.Green; 64 | Write(" Running Test: 0 %"); 65 | 66 | for (int cycle = 0; cycle < 10; cycle++) 67 | { 68 | for (int i = 0; i < 1000; i++) 69 | { 70 | test.Clear(); 71 | var length = random.Next(512); 72 | 73 | while (length-- > 0) 74 | { 75 | test.Append(charset, random.Next(charset.Length), 1); 76 | } 77 | 78 | var compressed = Smaz.Compress(test.ToString()); 79 | var decompressed = Smaz.Decompress(compressed); 80 | 81 | Assert.AreEqual(test.ToString(), decompressed, "Random failed for: '{0}'", test); 82 | } 83 | SetCursorPosition(19, CursorTop); 84 | Write($"{(cycle + 1) * 10:###} %"); 85 | } 86 | SetCursorPosition(0, CursorTop); 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /src/SmazSharpTests/Options.cs: -------------------------------------------------------------------------------- 1 | using CommandLine; 2 | using CommandLine.Text; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SmazSharpTests 10 | { 11 | public class Options 12 | { 13 | [Option('p', "perf", 14 | DefaultValue = false, 15 | HelpText = "Runs compression and decompression performance tests (same as: -c -d).")] 16 | public bool RunPerformance { get; set; } 17 | 18 | [Option('c', "compression", 19 | DefaultValue = false, 20 | HelpText = "Runs compression performance tests")] 21 | public bool RunPerformanceCompression { get; set; } 22 | 23 | [Option('d', "decompression", 24 | DefaultValue = false, 25 | HelpText = "Runs decompression performance tests")] 26 | public bool RunPerformanceDecompression { get; set; } 27 | 28 | [Option('c', "cycles", 29 | Required = false, DefaultValue = 10, 30 | HelpText = "Number of performance cycles to evaluate (with --perf)")] 31 | public int PerformanceCycles { get; set; } 32 | 33 | [Option('i', "iterations", 34 | Required = false, DefaultValue = 100000, 35 | HelpText = "Number of iterations within each performance cycle (with --perf)")] 36 | public int PerformanceIterations { get; set; } 37 | 38 | [ParserState] 39 | public IParserState LastParserState { get; set; } 40 | 41 | [HelpOption] 42 | public string GetUsage() 43 | { 44 | return HelpText.AutoBuild( 45 | this, 46 | ht => HelpText.DefaultParsingErrorsHandler(this, ht) 47 | ); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/SmazSharpTests/PerformanceTests.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SmazSharp; 3 | using System; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Text; 7 | using static System.Console; 8 | 9 | namespace SmazSharpTests 10 | { 11 | public class PerformanceTests 12 | { 13 | 14 | /// 15 | /// Test SmazSharp Compression Performance, assume compliance (via other tests) 16 | /// 17 | public void CompressPerfTest(int Cycles, int Iterations) 18 | { 19 | ForegroundColor = ConsoleColor.Yellow; 20 | WriteLine("------"); 21 | WriteLine("Testing Compression Performance"); 22 | ForegroundColor = ConsoleColor.Gray; 23 | WriteLine($" Cycles: {Cycles:N0}"); 24 | WriteLine($" Iterations: {Iterations:N0}"); 25 | 26 | #if DEBUG 27 | Assert.Inconclusive("Cannot run performance tests in Debug"); 28 | #endif 29 | Assert.IsTrue(Cycles > 0, "The number of Cycles must be greater than 0"); 30 | Assert.IsTrue(Iterations > 0, "The number of Iterations must be greater than 0"); 31 | 32 | ForegroundColor = ConsoleColor.Green; 33 | Write(" Running Tests: 0 %"); 34 | 35 | var testBytes = Resources.TestStrings.Select(s => Encoding.ASCII.GetBytes(s)).ToArray(); 36 | long[] results = new long[Cycles]; 37 | byte[] result; 38 | 39 | // Warm Up 40 | for (int i = 0; i < testBytes.Length; i++) 41 | { 42 | result = Smaz.Compress(testBytes[i]); 43 | } 44 | 45 | // Run Cycles 46 | for (int cycle = 0; cycle < Cycles; cycle++) 47 | { 48 | // Run Iterations 49 | Stopwatch sw = new Stopwatch(); 50 | sw.Start(); 51 | for (int iteration = 0; iteration < Iterations; iteration++) 52 | { 53 | Smaz.Decompress(testBytes[iteration % testBytes.Length]); 54 | } 55 | sw.Stop(); 56 | results[cycle] = sw.ElapsedTicks; 57 | SetCursorPosition(17, CursorTop); 58 | Write($"{(100 / (double)Cycles) * (cycle + 1):N0} %"); 59 | } 60 | 61 | SetCursorPosition(0, CursorTop); 62 | WriteLine(" Tests Complete "); 63 | WriteLine($" Cycles (ms): {string.Join(", ", results.Select(r => (r / TimeSpan.TicksPerMillisecond).ToString("N1")))}"); 64 | WriteLine($" Cycle Average: {results.Average() / TimeSpan.TicksPerMillisecond:N2} milliseconds"); 65 | WriteLine($" Average: {results.Average() / Iterations:N5} ticks/operation"); 66 | ForegroundColor = ConsoleColor.Yellow; 67 | WriteLine("Compression Performance Testing Complete"); 68 | WriteLine("------"); 69 | ForegroundColor = ConsoleColor.Gray; 70 | WriteLine(); 71 | } 72 | 73 | /// 74 | /// Test SmazSharp Decompression Performance, assume compliance (via other tests) 75 | /// 76 | public void DecompressPerfTest(int Cycles, int Iterations) 77 | { 78 | ForegroundColor = ConsoleColor.Yellow; 79 | WriteLine("------"); 80 | WriteLine("Testing Decompression Performance"); 81 | ForegroundColor = ConsoleColor.Gray; 82 | WriteLine($" Cycles: {Cycles:N0}"); 83 | WriteLine($" Iterations: {Iterations:N0}"); 84 | 85 | #if DEBUG 86 | Assert.Inconclusive("Cannot run performance tests in Debug"); 87 | #endif 88 | Assert.IsTrue(Cycles > 0, "The number of Cycles must be greater than 0"); 89 | Assert.IsTrue(Iterations > 0, "The number of Iterations must be greater than 0"); 90 | 91 | ForegroundColor = ConsoleColor.Green; 92 | Write(" Running Tests: 0 %"); 93 | 94 | var testBytes = Resources.TestStringsCompressed; 95 | long[] results = new long[Cycles]; 96 | string result; 97 | 98 | // Warm Up 99 | for (int i = 0; i < testBytes.Length; i++) 100 | { 101 | result = Smaz.Decompress(testBytes[i]); 102 | } 103 | 104 | // Run Cycles 105 | for (int cycle = 0; cycle < Cycles; cycle++) 106 | { 107 | // Run Iterations 108 | Stopwatch sw = new Stopwatch(); 109 | sw.Start(); 110 | for (int iteration = 0; iteration < Iterations; iteration++) 111 | { 112 | Smaz.Decompress(testBytes[iteration % testBytes.Length]); 113 | } 114 | sw.Stop(); 115 | results[cycle] = sw.ElapsedTicks; 116 | SetCursorPosition(17, CursorTop); 117 | Write($"{(100 / (double)Cycles) * (cycle + 1):N0} %"); 118 | } 119 | 120 | SetCursorPosition(0, CursorTop); 121 | WriteLine(" Tests Complete "); 122 | WriteLine($" Cycles (ms): {string.Join(", ", results.Select(r => (r / TimeSpan.TicksPerMillisecond).ToString("N1")))}"); 123 | WriteLine($" Cycle Average: {results.Average() / TimeSpan.TicksPerMillisecond:N2} milliseconds"); 124 | WriteLine($" Average: {results.Average() / Iterations:N5} ticks/operation"); 125 | ForegroundColor = ConsoleColor.Yellow; 126 | WriteLine("Decompression Performance Testing Complete"); 127 | WriteLine("------"); 128 | ForegroundColor = ConsoleColor.Gray; 129 | WriteLine(); 130 | } 131 | 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/SmazSharpTests/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | using static System.Console; 4 | 5 | namespace SmazSharpTests 6 | { 7 | static class Program 8 | { 9 | /// 10 | /// Entry point for stand-alone running 11 | /// 12 | static void Main(string[] args) 13 | { 14 | var options = new Options(); 15 | 16 | if (CommandLine.Parser.Default.ParseArgumentsStrict(args, options)) 17 | { 18 | try 19 | { 20 | ForegroundColor = ConsoleColor.Cyan; 21 | WriteLine("SmazSharp Tests"); 22 | WriteLine("Copyright © 2006 - 2009, Salvatore Sanfilippo"); 23 | WriteLine("This is free software.You may redistribute copies of it under the terms of"); 24 | WriteLine("the MIT License "); 25 | WriteLine(); 26 | 27 | // Perform Compliance Testing 28 | var complianceTests = new ComplianceTests(); 29 | 30 | ForegroundColor = ConsoleColor.Yellow; 31 | WriteLine("------"); 32 | WriteLine("Running Compliance Tests"); 33 | 34 | WriteLine(" Testing Compression"); 35 | ForegroundColor = ConsoleColor.Gray; 36 | complianceTests.CompressTest(); 37 | ForegroundColor = ConsoleColor.Green; 38 | WriteLine(" Test Passed"); 39 | 40 | ForegroundColor = ConsoleColor.Yellow; 41 | WriteLine(" Testing Decompression"); 42 | ForegroundColor = ConsoleColor.Gray; 43 | complianceTests.DecompressTest(); 44 | ForegroundColor = ConsoleColor.Green; 45 | WriteLine(" Test Passed"); 46 | 47 | ForegroundColor = ConsoleColor.Yellow; 48 | WriteLine(" Testing Random Compression->Decompression"); 49 | ForegroundColor = ConsoleColor.Gray; 50 | complianceTests.RandomTest(); 51 | ForegroundColor = ConsoleColor.Green; 52 | WriteLine(" Test Passed "); 53 | 54 | ForegroundColor = ConsoleColor.Yellow; 55 | WriteLine("Compliance Testing Completed"); 56 | WriteLine("------"); 57 | WriteLine(); 58 | ForegroundColor = ConsoleColor.Gray; 59 | 60 | if (options.RunPerformance || options.RunPerformanceCompression) 61 | { 62 | var performanceTests = new PerformanceTests(); 63 | 64 | performanceTests.CompressPerfTest(options.PerformanceCycles, options.PerformanceIterations); 65 | } 66 | 67 | if (options.RunPerformance || options.RunPerformanceDecompression) 68 | { 69 | var performanceTests = new PerformanceTests(); 70 | 71 | performanceTests.DecompressPerfTest(options.PerformanceCycles, options.PerformanceIterations); 72 | } 73 | } 74 | catch (UnitTestAssertException ex) 75 | { 76 | Console.WriteLine(); 77 | Console.ForegroundColor = ConsoleColor.Red; 78 | Console.WriteLine(ex.Message); 79 | Console.ForegroundColor = ConsoleColor.Gray; 80 | Console.WriteLine(); 81 | } 82 | } 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/SmazSharpTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using CommandLine; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("SmazSharp Tests")] 10 | [assembly: AssemblyDescription("Tests for SmazSharp")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("SmazSharp Tests")] 14 | [assembly: AssemblyCopyright("Copyright © 2006-2009, Salvatore Sanfilippo")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | [assembly: AssemblyLicense( 19 | "This is free software. You may redistribute copies of it under the terms of", 20 | "the MIT License ")] 21 | [assembly: AssemblyUsage( 22 | "Usage: SmazSharpTests.exe -p")] 23 | 24 | // Setting ComVisible to false makes the types in this assembly not visible 25 | // to COM components. If you need to access a type in this assembly from 26 | // COM, set the ComVisible attribute to true on that type. 27 | [assembly: ComVisible(false)] 28 | 29 | // The following GUID is for the ID of the typelib if this project is exposed to COM 30 | [assembly: Guid("09132478-d059-49c8-884b-19d99ac5ea9f")] 31 | 32 | // Version information for an assembly consists of the following four values: 33 | // 34 | // Major Version 35 | // Minor Version 36 | // Build Number 37 | // Revision 38 | // 39 | // You can specify all the values or you can default the Build and Revision Numbers 40 | // by using the '*' as shown below: 41 | // [assembly: AssemblyVersion("1.0.*")] 42 | [assembly: AssemblyVersion("0.1.0.0")] 43 | [assembly: AssemblyFileVersion("0.1.0.0")] 44 | -------------------------------------------------------------------------------- /src/SmazSharpTests/Resources.cs: -------------------------------------------------------------------------------- 1 | namespace SmazSharpTests 2 | { 3 | public static class Resources 4 | { 5 | 6 | /// 7 | /// Strings used for Testing 8 | /// 9 | public static readonly string[] TestStrings = new string[] { 10 | @"This is a small string", 11 | @"foobar", 12 | @"the end", 13 | @"not-a-g00d-Exampl333", 14 | @"Smaz is a simple compression library", 15 | @"Nothing is more difficult, and therefore more precious, than to be able to decide", 16 | @"this is an example of what works very well with smaz", 17 | @"1000 numbers 2000 will 10 20 30 compress very little", 18 | @"and now a few italian sentences:", 19 | @"Nel mezzo del cammin di nostra vita, mi ritrovai in una selva oscura", 20 | @"Mi illumino di immenso", 21 | @"L'autore di questa libreria vive in Sicilia", 22 | @"try it against urls", 23 | @"http://google.com", 24 | @"http://programming.reddit.com", 25 | @"http://github.com/antirez/smaz/tree/master", 26 | @"/media/hdb1/music/Alben/The Bla", 27 | }; 28 | 29 | /// 30 | /// Verified encoded data for TestStrings (from original C Smaz code) 31 | /// 32 | public static readonly byte[][] TestStringsCompressed = new byte[][] 33 | { 34 | /* 'This is a small string' */ 35 | new byte[] {254, 84, 76, 56, 172, 62, 173, 152, 62, 195, 70}, 36 | /* 'foobar' */ 37 | new byte[] {220, 6, 90, 79}, 38 | /* 'the end' */ 39 | new byte[] {1, 171, 61}, 40 | /* 'not-a-g00d-Exampl333' */ 41 | new byte[] {132, 204, 4, 204, 59, 255, 2, 48, 48, 24, 204, 254, 69, 250, 4, 45, 60, 22, 255, 3, 51, 51, 51}, 42 | /* 'Smaz is a simple compression library' */ 43 | new byte[] {254, 83, 173, 219, 56, 172, 62, 226, 60, 87, 161, 45, 60, 33, 166, 107, 205, 8, 90, 130, 12, 83}, 44 | /* 'Nothing is more difficult, and therefore more precious, than to be able to decide' */ 45 | new byte[] {254, 78, 223, 102, 99, 116, 45, 42, 11, 129, 44, 44, 131, 38, 22, 3, 148, 63, 210, 68, 11, 45, 42, 11, 60, 33, 28, 144, 164, 36, 203, 143, 96, 92, 25, 90, 87, 82, 165, 215, 237, 2}, 46 | /* 'this is an example of what works very well with smaz' */ 47 | new byte[] {155, 56, 172, 41, 2, 250, 4, 45, 60, 87, 32, 159, 135, 65, 42, 254, 107, 23, 231, 71, 145, 152, 243, 227, 10, 173, 219}, 48 | /* '1000 numbers 2000 will 10 20 30 compress very little' */ 49 | new byte[] {255, 4, 49, 48, 48, 48, 236, 38, 45, 92, 221, 0, 255, 4, 50, 48, 48, 48, 243, 152, 0, 255, 2, 49, 48, 0, 255, 2, 50, 48, 0, 255, 2, 51, 48, 161, 45, 60, 33, 166, 0, 231, 71, 151, 3, 3, 87}, 50 | /* 'and now a few italian sentences:' */ 51 | new byte[] {7, 236, 6, 65, 146, 44, 2, 65, 246, 88, 8, 26, 62, 97, 51, 136, 10, 254, 58}, 52 | /* 'Nel mezzo del cammin di nostra vita, mi ritrovai in una selva oscura' */ 53 | new byte[] {254, 78, 178, 123, 2, 219, 219, 96, 106, 180, 28, 4, 45, 45, 105, 129, 236, 6, 77, 130, 0, 109, 47, 4, 36, 45, 8, 189, 47, 115, 109, 4, 8, 78, 0, 224, 163, 95, 22, 109, 163, 6, 10, 28, 150, 4}, 54 | /* 'Mi illumino di immenso' */ 55 | new byte[] {254, 77, 8, 56, 152, 38, 45, 15, 96, 129, 56, 45, 252, 179}, 56 | /* 'L'autore di questa libreria vive in Sicilia' */ 57 | new byte[] {255, 2, 76, 39, 4, 196, 42, 11, 129, 0, 254, 113, 38, 54, 200, 205, 8, 90, 33, 114, 163, 109, 186, 11, 105, 254, 83, 131, 240, 8, 4}, 58 | /* 'try it against urls' */ 59 | new byte[] {195, 71, 47, 25, 59, 4, 15, 77, 0, 150, 22, 10}, 60 | /* 'http://google.com' */ 61 | new byte[] {67, 59, 6, 6, 59, 87, 253}, 62 | /* 'http://programming.reddit.com' */ 63 | new byte[] {67, 60, 115, 59, 130, 45, 45, 70, 110, 33, 24, 129, 3, 253}, 64 | /* 'http://github.com/antirez/smaz/tree/master' */ 65 | new byte[] {67, 59, 47, 18, 38, 90, 253, 197, 26, 74, 33, 219, 197, 10, 173, 219, 197, 195, 235, 197, 173, 77, 27}, 66 | /* '/media/hdb1/music/Alben/The Bla' */ 67 | new byte[] {197, 108, 129, 4, 197, 18, 24, 90, 254, 49, 197, 45, 164, 131, 197, 254, 65, 22, 92, 9, 197, 72, 0, 254, 66, 137} 68 | }; 69 | 70 | /// 71 | /// Character Set for Random Tests 72 | /// 73 | public const string TestCharSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz/. "; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/SmazSharpTests/SmazSharpTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {09132478-D059-49C8-884B-19D99AC5EA9F} 7 | Exe 8 | Properties 9 | SmazSharpTests 10 | SmazSharpTests 11 | v4.5.2 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | 40 | 41 | 42 | 43 | ..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll 44 | True 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | {9ABB67FC-CE56-40B1-8F4B-48F59C89ADFD} 71 | SmazSharp 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | False 82 | 83 | 84 | False 85 | 86 | 87 | False 88 | 89 | 90 | False 91 | 92 | 93 | 94 | 95 | 96 | 97 | 104 | -------------------------------------------------------------------------------- /src/SmazSharpTests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | --------------------------------------------------------------------------------