Huge Resharper clean up. Fixed up test project.json

This commit is contained in:
Adam Hathcock
2016-09-26 10:55:52 +01:00
parent ddbbc3b847
commit efa6f7a82e
209 changed files with 6919 additions and 6162 deletions

View File

@@ -1,6 +1,119 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=181069325DAB1C4287CD564D6CDDEDB3/AbsolutePath/@EntryValue">D:\Git\sharpcompress\SharpCompress\sharpcompress.DotSettings</s:String>
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=181069325DAB1C4287CD564D6CDDEDB3/RelativePath/@EntryValue">..\SharpCompress\sharpcompress.DotSettings</s:String>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=181069325DAB1C4287CD564D6CDDEDB3/@KeyIndexDefined">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File181069325DAB1C4287CD564D6CDDEDB3/@KeyIndexDefined">True</s:Boolean>
<s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File181069325DAB1C4287CD564D6CDDEDB3/RelativePriority/@EntryValue">1</s:Double></wpf:ResourceDictionary>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArgumentsStyleNamedExpression/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeBraces_005Fdowhile/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeBraces_005Ffixed/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeBraces_005Ffor/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeBraces_005Fforeach/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeBraces_005Fifelse/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeBraces_005Flock/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeBraces_005Fusing/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeBraces_005Fwhile/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MethodSupportsCancellation/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantExplicitParamsArrayCreation/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Basic_0020Clean/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="Basic Clean"&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;EmbraceInRegion&gt;False&lt;/EmbraceInRegion&gt;&lt;RegionName&gt;&lt;/RegionName&gt;&lt;/CSOptimizeUsings&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;CSRemoveCodeRedundancies&gt;True&lt;/CSRemoveCodeRedundancies&gt;&lt;CSMakeFieldReadonly&gt;True&lt;/CSMakeFieldReadonly&gt;&lt;CSCodeStyleAttributes ArrangeTypeAccessModifier="False" ArrangeTypeMemberAccessModifier="False" SortModifiers="False" RemoveRedundantParentheses="False" AddMissingParentheses="False" ArrangeBraces="True" ArrangeAttributes="False" ArrangeArgumentsStyle="False" /&gt;&lt;RemoveCodeRedundancies&gt;True&lt;/RemoveCodeRedundancies&gt;&lt;CSUseAutoProperty&gt;True&lt;/CSUseAutoProperty&gt;&lt;CSMakeAutoPropertyGetOnly&gt;True&lt;/CSMakeAutoPropertyGetOnly&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;/Profile&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/SilentCleanupProfile/@EntryValue">Basic Clean</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/APPLY_ON_COMPLETION/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ARGUMENTS_NAMED/@EntryValue">Named</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_FOR/@EntryValue">Required</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_FOREACH/@EntryValue">Required</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_IFELSE/@EntryValue">Required</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_WHILE/@EntryValue">Required</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_FIRST_ARG_BY_PAREN/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_LINQ_QUERY/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_ARGUMENT/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_ARRAY_AND_OBJECT_INITIALIZER/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_EXPRESSION/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_FOR_STMT/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_PARAMETER/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTIPLE_DECLARATION/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTLINE_TYPE_PARAMETER_CONSTRAINS/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTLINE_TYPE_PARAMETER_LIST/@EntryValue">True</s:Boolean>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_AFTER_START_COMMENT/@EntryValue">0</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_BEFORE_SINGLE_LINE_COMMENT/@EntryValue">1</s:Int64>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_ATTRIBUTE_STYLE/@EntryValue">SEPARATE</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_FIXED_BRACES_STYLE/@EntryValue">ALWAYS_ADD</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_FOR_BRACES_STYLE/@EntryValue">ALWAYS_ADD</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_FOREACH_BRACES_STYLE/@EntryValue">ALWAYS_ADD</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_IFELSE_BRACES_STYLE/@EntryValue">ALWAYS_ADD</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_USING_BRACES_STYLE/@EntryValue">ALWAYS_ADD</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/FORCE_WHILE_BRACES_STYLE/@EntryValue">ALWAYS_ADD</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_ANONYMOUS_METHOD_BLOCK/@EntryValue">True</s:Boolean>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_CODE/@EntryValue">1</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue">1</s:Int64>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_CONSTRUCTOR_INITIALIZER_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ACCESSORHOLDER_ON_SINGLE_LINE/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ACCESSOR_ATTRIBUTE_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_INITIALIZER_ON_SINGLE_LINE/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_WHILE_ON_NEW_LINE/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SIMPLE_EMBEDDED_STATEMENT_STYLE/@EntryValue">LINE_BREAK</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AROUND_ARROW_OP/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AROUND_MULTIPLICATIVE_OP/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BEFORE_SIZEOF_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BEFORE_TYPEOF_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/STICK_COMMENT/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_ARGUMENTS_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_ARRAY_INITIALIZER_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_EXTENDS_LIST_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_PARAMETERS_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForBuiltInTypes/@EntryValue">UseVarWhenEvident</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseVarWhenEvident</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseVarWhenEvident</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FBLOCK_005FSCOPE_005FCONSTANT/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FBLOCK_005FSCOPE_005FFUNCTION/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FBLOCK_005FSCOPE_005FVARIABLE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FCLASS/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FCONSTRUCTOR/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FFUNCTION/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FGLOBAL_005FVARIABLE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FLABEL/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FLOCAL_005FCONSTRUCTOR/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FLOCAL_005FVARIABLE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FOBJECT_005FPROPERTY_005FOF_005FFUNCTION/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FPARAMETER/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FCLASS/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FENUM/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FENUM_005FMEMBER/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FINTERFACE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FMODULE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FMODULE_005FEXPORTED/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FMODULE_005FLOCAL/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FPRIVATE_005FMEMBER_005FACCESSOR/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FPRIVATE_005FSTATIC_005FTYPE_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FPRIVATE_005FTYPE_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FPRIVATE_005FTYPE_005FMETHOD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FPROTECTED_005FMEMBER_005FACCESSOR/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FPROTECTED_005FSTATIC_005FTYPE_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FPROTECTED_005FTYPE_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FPROTECTED_005FTYPE_005FMETHOD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FPUBLIC_005FMEMBER_005FACCESSOR/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FPUBLIC_005FSTATIC_005FTYPE_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FPUBLIC_005FTYPE_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FPUBLIC_005FTYPE_005FMETHOD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=TS_005FTYPE_005FPARAMETER/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/WebNaming/UserRules/=ASP_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/WebNaming/UserRules/=ASP_005FHTML_005FCONTROL/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/WebNaming/UserRules/=ASP_005FTAG_005FNAME/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/WebNaming/UserRules/=ASP_005FTAG_005FPREFIX/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=NAMESPACE_005FALIAS/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FRESOURCE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@@ -54,7 +54,8 @@ namespace SharpCompress.Archive
lazyVolumes = new LazyReadOnlyCollection<TVolume>(Enumerable.Empty<TVolume>());
lazyEntries = new LazyReadOnlyCollection<TEntry>(Enumerable.Empty<TEntry>());
}
public ArchiveType Type { get; private set; }
public ArchiveType Type { get; }
void IArchiveExtractionListener.FireEntryExtractionBegin(IArchiveEntry entry)
{
@@ -84,47 +85,29 @@ namespace SharpCompress.Archive
/// <summary>
/// Returns an ReadOnlyCollection of all the RarArchiveEntries across the one or many parts of the RarArchive.
/// </summary>
public virtual ICollection<TEntry> Entries
{
get { return lazyEntries; }
}
public virtual ICollection<TEntry> Entries { get { return lazyEntries; } }
/// <summary>
/// Returns an ReadOnlyCollection of all the RarArchiveVolumes across the one or many parts of the RarArchive.
/// </summary>
public ICollection<TVolume> Volumes
{
get { return lazyVolumes; }
}
public ICollection<TVolume> Volumes { get { return lazyVolumes; } }
/// <summary>
/// The total size of the files compressed in the archive.
/// </summary>
public virtual long TotalSize
{
get { return Entries.Aggregate(0L, (total, cf) => total + cf.CompressedSize); }
}
public virtual long TotalSize { get { return Entries.Aggregate(0L, (total, cf) => total + cf.CompressedSize); } }
/// <summary>
/// The total size of the files as uncompressed in the archive.
/// </summary>
public virtual long TotalUncompressSize
{
get { return Entries.Aggregate(0L, (total, cf) => total + cf.Size); }
}
public virtual long TotalUncompressSize { get { return Entries.Aggregate(0L, (total, cf) => total + cf.Size); } }
protected abstract IEnumerable<TVolume> LoadVolumes(IEnumerable<Stream> streams, Options options);
protected abstract IEnumerable<TEntry> LoadEntries(IEnumerable<TVolume> volumes);
IEnumerable<IArchiveEntry> IArchive.Entries
{
get { return Entries.Cast<IArchiveEntry>(); }
}
IEnumerable<IArchiveEntry> IArchive.Entries { get { return Entries.Cast<IArchiveEntry>(); } }
IEnumerable<IVolume> IArchive.Volumes
{
get { return lazyVolumes.Cast<IVolume>(); }
}
IEnumerable<IVolume> IArchive.Volumes { get { return lazyVolumes.Cast<IVolume>(); } }
private bool disposed;
@@ -148,11 +131,11 @@ namespace SharpCompress.Archive
{
if (CompressedBytesRead != null)
{
CompressedBytesRead(this, new CompressedBytesReadEventArgs()
{
CurrentFilePartCompressedBytesRead = currentPartCompressedBytes,
CompressedBytesRead = compressedReadBytes
});
CompressedBytesRead(this, new CompressedBytesReadEventArgs
{
CurrentFilePartCompressedBytesRead = currentPartCompressedBytes,
CompressedBytesRead = compressedReadBytes
});
}
}
@@ -160,12 +143,12 @@ namespace SharpCompress.Archive
{
if (FilePartExtractionBegin != null)
{
FilePartExtractionBegin(this, new FilePartExtractionBeginEventArgs()
{
CompressedSize = compressedSize,
Size = size,
Name = name,
});
FilePartExtractionBegin(this, new FilePartExtractionBeginEventArgs
{
CompressedSize = compressedSize,
Size = size,
Name = name
});
}
}
@@ -191,11 +174,7 @@ namespace SharpCompress.Archive
/// <summary>
/// Archive is SOLID (this means the Archive saved bytes by reusing information which helps for archives containing many small files).
/// </summary>
public virtual bool IsSolid
{
get { return false; }
}
public virtual bool IsSolid { get { return false; } }
/// <summary>
/// The archive can find all the parts of the archive needed to fully extract the archive. This forces the parsing of the entire archive.

View File

@@ -53,10 +53,7 @@ namespace SharpCompress.Archive
modifiedEntries.AddRange(OldEntries.Concat(newEntries));
}
private IEnumerable<TEntry> OldEntries
{
get { return base.Entries.Where(x => !removedEntries.Contains(x)); }
}
private IEnumerable<TEntry> OldEntries { get { return base.Entries.Where(x => !removedEntries.Contains(x)); } }
public void RemoveEntry(TEntry entry)
{
@@ -66,25 +63,25 @@ namespace SharpCompress.Archive
RebuildModifiedCollection();
}
}
void IWritableArchive.RemoveEntry(IArchiveEntry entry)
{
RemoveEntry((TEntry)entry);
}
public TEntry AddEntry(string key, Stream source,
long size = 0, DateTime? modified = null)
long size = 0, DateTime? modified = null)
{
return AddEntry(key, source, false, size, modified);
}
IArchiveEntry IWritableArchive.AddEntry(string key, Stream source, bool closeStream, long size, DateTime? modified)
{
return AddEntry(key, source, closeStream, size, modified);
}
public TEntry AddEntry(string key, Stream source, bool closeStream,
long size = 0, DateTime? modified = null)
long size = 0, DateTime? modified = null)
{
if (key.StartsWith("/")
|| key.StartsWith("\\"))
@@ -105,7 +102,7 @@ namespace SharpCompress.Archive
{
foreach (var path in Entries.Select(x => x.Key))
{
var p = path.Replace('/','\\');
var p = path.Replace('/', '\\');
if (p.StartsWith("\\"))
{
p = p.Substring(1);
@@ -123,7 +120,7 @@ namespace SharpCompress.Archive
}
protected TEntry CreateEntry(string key, Stream source, long size, DateTime? modified,
bool closeStream)
bool closeStream)
{
if (!source.CanRead || !source.CanSeek)
{
@@ -133,7 +130,7 @@ namespace SharpCompress.Archive
}
protected abstract TEntry CreateEntryInternal(string key, Stream source, long size, DateTime? modified,
bool closeStream);
bool closeStream);
protected abstract void SaveTo(Stream stream, CompressionInfo compressionType,
IEnumerable<TEntry> oldEntries, IEnumerable<TEntry> newEntries);

View File

@@ -45,8 +45,8 @@ namespace SharpCompress.Archive
stream.Seek(0, SeekOrigin.Begin);
if (RarArchive.IsRarFile(stream, options))
{
stream.Seek(0, SeekOrigin.Begin);
return RarArchive.Open(stream, options);
stream.Seek(0, SeekOrigin.Begin);
return RarArchive.Open(stream, options);
}
stream.Seek(0, SeekOrigin.Begin);
if (TarArchive.IsTarFile(stream))
@@ -62,29 +62,30 @@ namespace SharpCompress.Archive
switch (type)
{
case ArchiveType.Zip:
{
return ZipArchive.Create();
}
{
return ZipArchive.Create();
}
case ArchiveType.Tar:
{
return TarArchive.Create();
}
{
return TarArchive.Create();
}
case ArchiveType.GZip:
{
return GZipArchive.Create();
}
{
return GZipArchive.Create();
}
default:
{
throw new NotSupportedException("Cannot create Archives of type: " + type);
}
{
throw new NotSupportedException("Cannot create Archives of type: " + type);
}
}
}
#if !NO_FILE
/// <summary>
/// Constructor expects a filepath to an existing file.
/// </summary>
/// <param name="filePath"></param>
/// <summary>
/// Constructor expects a filepath to an existing file.
/// </summary>
/// <param name="filePath"></param>
public static IArchive Open(string filePath)
{
return Open(filePath, Options.None);

View File

@@ -13,10 +13,11 @@ namespace SharpCompress.Archive.GZip
public class GZipArchive : AbstractWritableArchive<GZipArchiveEntry, GZipVolume>
{
#if !NO_FILE
/// <summary>
/// Constructor expects a filepath to an existing file.
/// </summary>
/// <param name="filePath"></param>
/// <summary>
/// Constructor expects a filepath to an existing file.
/// </summary>
/// <param name="filePath"></param>
public static GZipArchive Open(string filePath)
{
return Open(filePath, Options.None);
@@ -81,11 +82,12 @@ namespace SharpCompress.Archive.GZip
}
#if !NO_FILE
/// <summary>
/// Constructor with a FileInfo object to an existing file.
/// </summary>
/// <param name="fileInfo"></param>
/// <param name="options"></param>
/// <summary>
/// Constructor with a FileInfo object to an existing file.
/// </summary>
/// <param name="fileInfo"></param>
/// <param name="options"></param>
internal GZipArchive(FileInfo fileInfo, Options options)
: base(ArchiveType.GZip, fileInfo, options)
{
@@ -135,13 +137,19 @@ namespace SharpCompress.Archive.GZip
// workitem 8501: handle edge case (decompress empty stream)
if (n == 0)
{
return false;
}
if (n != 10)
{
return false;
}
if (header[0] != 0x1F || header[1] != 0x8B || header[2] != 8)
{
return false;
}
return true;
}
@@ -167,7 +175,7 @@ namespace SharpCompress.Archive.GZip
}
protected override GZipArchiveEntry CreateEntryInternal(string filePath, Stream source, long size, DateTime? modified,
bool closeStream)
bool closeStream)
{
if (Entries.Any())
{

View File

@@ -6,7 +6,6 @@ namespace SharpCompress.Archive.GZip
{
public class GZipArchiveEntry : GZipEntry, IArchiveEntry
{
internal GZipArchiveEntry(GZipArchive archive, GZipFilePart part)
: base(part)
{
@@ -19,12 +18,10 @@ namespace SharpCompress.Archive.GZip
}
#region IArchiveEntry Members
public IArchive Archive { get; private set; }
public bool IsComplete
{
get { return true; }
}
public IArchive Archive { get; }
public bool IsComplete { get { return true; } }
#endregion
}

View File

@@ -8,9 +8,6 @@ namespace SharpCompress.Archive.GZip
{
internal class GZipWritableArchiveEntry : GZipArchiveEntry, IWritableArchiveEntry
{
private readonly string path;
private readonly long size;
private readonly DateTime? lastModified;
private readonly bool closeStream;
private readonly Stream stream;
@@ -19,79 +16,37 @@ namespace SharpCompress.Archive.GZip
: base(archive, null)
{
this.stream = stream;
this.path = path;
this.size = size;
this.lastModified = lastModified;
Key = path;
Size = size;
LastModifiedTime = lastModified;
this.closeStream = closeStream;
}
public override long Crc
{
get { return 0; }
}
public override long Crc { get { return 0; } }
public override string Key
{
get { return path; }
}
public override string Key { get; }
public override long CompressedSize
{
get { return 0; }
}
public override long CompressedSize { get { return 0; } }
public override long Size
{
get { return size; }
}
public override long Size { get; }
public override DateTime? LastModifiedTime
{
get { return lastModified; }
}
public override DateTime? LastModifiedTime { get; }
public override DateTime? CreatedTime
{
get { return null; }
}
public override DateTime? CreatedTime { get { return null; } }
public override DateTime? LastAccessedTime
{
get { return null; }
}
public override DateTime? LastAccessedTime { get { return null; } }
public override DateTime? ArchivedTime
{
get { return null; }
}
public override DateTime? ArchivedTime { get { return null; } }
public override bool IsEncrypted
{
get { return false; }
}
public override bool IsEncrypted { get { return false; } }
public override bool IsDirectory
{
get { return false; }
}
public override bool IsDirectory { get { return false; } }
public override bool IsSplit
{
get { return false; }
}
public override bool IsSplit { get { return false; } }
internal override IEnumerable<FilePart> Parts
{
get { throw new NotImplementedException(); }
}
internal override IEnumerable<FilePart> Parts { get { throw new NotImplementedException(); } }
Stream IWritableArchiveEntry.Stream
{
get
{
return stream;
}
}
Stream IWritableArchiveEntry.Stream { get { return stream; } }
public override Stream OpenEntryStream()
{

View File

@@ -1,14 +1,12 @@
using System.Linq;
using SharpCompress.Common;
namespace SharpCompress.Archive
namespace SharpCompress.Archive
{
public static class IArchiveExtensions
{
#if !NO_FILE
/// <summary>
/// Extract to specific directory, retaining filename
/// </summary>
/// <summary>
/// Extract to specific directory, retaining filename
/// </summary>
public static void WriteToDirectory(this IArchive archive, string destinationDirectory,
ExtractOptions options = ExtractOptions.Overwrite)
{

View File

@@ -28,17 +28,20 @@ namespace SharpCompress.Archive
return;
}
using (entryStream)
using (Stream s = new ListeningStream(streamListener, entryStream))
{
s.TransferTo(streamToWriteTo);
using (Stream s = new ListeningStream(streamListener, entryStream))
{
s.TransferTo(streamToWriteTo);
}
}
streamListener.FireEntryExtractionEnd(archiveEntry);
}
#if !NO_FILE
/// <summary>
/// Extract to specific directory, retaining filename
/// </summary>
/// <summary>
/// Extract to specific directory, retaining filename
/// </summary>
public static void WriteToDirectory(this IArchiveEntry entry, string destinationDirectory,
ExtractOptions options = ExtractOptions.Overwrite)
{

View File

@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using SharpCompress.Common;
namespace SharpCompress.Archive
@@ -7,7 +6,7 @@ namespace SharpCompress.Archive
public static class IWritableArchiveExtensions
{
public static void SaveTo(this IWritableArchive writableArchive,
Stream stream, CompressionType compressionType)
Stream stream, CompressionType compressionType)
{
writableArchive.SaveTo(stream, new CompressionInfo {Type = compressionType});
}

View File

@@ -1,4 +1,5 @@
#if !NO_FILE
#if !NO_FILE
using System.Collections.Generic;
using System.IO;
using SharpCompress.Common;

View File

@@ -1,4 +1,5 @@
#if !NO_FILE
#if !NO_FILE
using System.IO;
using SharpCompress.Common.Rar;
using SharpCompress.Common.Rar.Headers;

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -14,20 +13,16 @@ namespace SharpCompress.Archive.Rar
{
public class RarArchive : AbstractArchive<RarArchiveEntry, RarVolume>
{
private readonly Unpack unpack = new Unpack();
internal Unpack Unpack
{
get { return unpack; }
}
internal Unpack Unpack { get; } = new Unpack();
#if !NO_FILE
/// <summary>
/// Constructor with a FileInfo object to an existing file.
/// </summary>
/// <param name="fileInfo"></param>
/// <param name="options"></param>
/// <param name="password"></param>
/// <summary>
/// Constructor with a FileInfo object to an existing file.
/// </summary>
/// <param name="fileInfo"></param>
/// <param name="options"></param>
/// <param name="password"></param>
internal RarArchive(FileInfo fileInfo, Options options, string password)
: base(ArchiveType.Rar, fileInfo, options, password)
{
@@ -67,20 +62,18 @@ namespace SharpCompress.Archive.Rar
return RarReader.Open(stream, Password);
}
public override bool IsSolid
{
get { return Volumes.First().IsSolidArchive; }
}
public override bool IsSolid { get { return Volumes.First().IsSolidArchive; } }
#region Creation
#if !NO_FILE
/// <summary>
/// Constructor expects a filepath to an existing file.
/// </summary>
/// <param name="filePath"></param>
/// <param name="options"></param>
/// <param name="password"></param>
/// <summary>
/// Constructor expects a filepath to an existing file.
/// </summary>
/// <param name="filePath"></param>
/// <param name="options"></param>
/// <param name="password"></param>
public static RarArchive Open(string filePath, Options options = Options.None, string password = null)
{
filePath.CheckNotNullOrEmpty("filePath");
@@ -99,6 +92,7 @@ namespace SharpCompress.Archive.Rar
return new RarArchive(fileInfo, options, password);
}
#endif
/// <summary>
/// Takes a seekable Stream as a source
/// </summary>

View File

@@ -20,28 +20,13 @@ namespace SharpCompress.Archive.Rar
this.archive = archive;
}
public override CompressionType CompressionType
{
get { return CompressionType.Rar; }
}
public override CompressionType CompressionType { get { return CompressionType.Rar; } }
public IArchive Archive
{
get
{
return archive;
}
}
public IArchive Archive { get { return archive; } }
internal override IEnumerable<FilePart> Parts
{
get { return parts.Cast<FilePart>(); }
}
internal override IEnumerable<FilePart> Parts { get { return parts.Cast<FilePart>(); } }
internal override FileHeader FileHeader
{
get { return parts.First().FileHeader; }
}
internal override FileHeader FileHeader { get { return parts.First().FileHeader; } }
public override long Crc
{
@@ -49,11 +34,10 @@ namespace SharpCompress.Archive.Rar
{
CheckIncomplete();
return parts.Select(fp => fp.FileHeader)
.Single(fh => !fh.FileFlags.HasFlag(FileFlags.SPLIT_AFTER)).FileCRC;
.Single(fh => !fh.FileFlags.HasFlag(FileFlags.SPLIT_AFTER)).FileCRC;
}
}
public override long Size
{
get
@@ -81,10 +65,7 @@ namespace SharpCompress.Archive.Rar
return new RarStream(archive.Unpack, FileHeader, new MultiVolumeReadOnlyStream(Parts.Cast<RarFilePart>(), archive));
}
public bool IsComplete
{
get { return parts.Select(fp => fp.FileHeader).Any(fh => !fh.FileFlags.HasFlag(FileFlags.SPLIT_AFTER)); }
}
public bool IsComplete { get { return parts.Select(fp => fp.FileHeader).Any(fh => !fh.FileFlags.HasFlag(FileFlags.SPLIT_AFTER)); } }
private void CheckIncomplete()
{

View File

@@ -25,7 +25,7 @@ namespace SharpCompress.Archive.Rar
{
groupedParts.Add(fp);
if (!FlagUtility.HasFlag((long) fp.FileHeader.FileFlags, (long) FileFlags.SPLIT_AFTER))
if (!FlagUtility.HasFlag((long)fp.FileHeader.FileFlags, (long)FileFlags.SPLIT_AFTER))
{
yield return groupedParts;
groupedParts = new List<RarFilePart>();

View File

@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using SharpCompress.Common.Rar.Headers;
using SharpCompress.Common;
using SharpCompress.Common.Rar;

View File

@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using SharpCompress.Common.Rar;
using SharpCompress.Common.Rar.Headers;
@@ -29,9 +28,6 @@ namespace SharpCompress.Archive.Rar
return stream;
}
internal override string FilePartName
{
get { return "Unknown Stream - File Entry: " + FileHeader.FileName; }
}
internal override string FilePartName { get { return "Unknown Stream - File Entry: " + FileHeader.FileName; } }
}
}

View File

@@ -13,10 +13,11 @@ namespace SharpCompress.Archive.SevenZip
{
private ArchiveDatabase database;
#if !NO_FILE
/// <summary>
/// Constructor expects a filepath to an existing file.
/// </summary>
/// <param name="filePath"></param>
/// <summary>
/// Constructor expects a filepath to an existing file.
/// </summary>
/// <param name="filePath"></param>
public static SevenZipArchive Open(string filePath)
{
return Open(filePath, Options.None);
@@ -156,7 +157,6 @@ namespace SharpCompress.Archive.SevenZip
}
}
public static bool IsSevenZipFile(Stream stream)
{
try
@@ -169,7 +169,7 @@ namespace SharpCompress.Archive.SevenZip
}
}
private static readonly byte[] SIGNATURE = new byte[] {(byte) '7', (byte) 'z', 0xBC, 0xAF, 0x27, 0x1C};
private static readonly byte[] SIGNATURE = {(byte)'7', (byte)'z', 0xBC, 0xAF, 0x27, 0x1C};
private static bool SignatureMatch(Stream stream)
{
@@ -183,10 +183,7 @@ namespace SharpCompress.Archive.SevenZip
return new SevenZipReader(this);
}
public override bool IsSolid
{
get { return Entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder).Count() > 1; }
}
public override bool IsSolid { get { return Entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder).Count() > 1; } }
public override long TotalSize
{
@@ -210,11 +207,7 @@ namespace SharpCompress.Archive.SevenZip
this.archive = archive;
}
public override SevenZipVolume Volume
{
get { return archive.Volumes.Single(); }
}
public override SevenZipVolume Volume { get { return archive.Volumes.Single(); } }
internal override IEnumerable<SevenZipEntry> GetEntries(Stream stream)
{

View File

@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using SharpCompress.Common.SevenZip;
namespace SharpCompress.Archive.SevenZip
@@ -16,19 +15,14 @@ namespace SharpCompress.Archive.SevenZip
{
return FilePart.GetCompressedStream();
}
public IArchive Archive { get; private set; }
public bool IsComplete
{
get { return true; }
}
public IArchive Archive { get; }
public bool IsComplete { get { return true; } }
/// <summary>
/// This is a 7Zip Anti item
/// </summary>
public bool IsAnti
{
get { return FilePart.Header.IsAnti; }
}
public bool IsAnti { get { return FilePart.Header.IsAnti; } }
}
}

View File

@@ -15,10 +15,11 @@ namespace SharpCompress.Archive.Tar
public class TarArchive : AbstractWritableArchive<TarArchiveEntry, TarVolume>
{
#if !NO_FILE
/// <summary>
/// Constructor expects a filepath to an existing file.
/// </summary>
/// <param name="filePath"></param>
/// <summary>
/// Constructor expects a filepath to an existing file.
/// </summary>
/// <param name="filePath"></param>
public static TarArchive Open(string filePath)
{
return Open(filePath, Options.None);
@@ -102,7 +103,7 @@ namespace SharpCompress.Archive.Tar
{
TarHeader tar = new TarHeader();
tar.Read(new BinaryReader(stream));
return tar.Name.Length > 0 && Enum.IsDefined(typeof (EntryType), tar.EntryType);
return tar.Name.Length > 0 && Enum.IsDefined(typeof(EntryType), tar.EntryType);
}
catch
{
@@ -111,11 +112,12 @@ namespace SharpCompress.Archive.Tar
}
#if !NO_FILE
/// <summary>
/// Constructor with a FileInfo object to an existing file.
/// </summary>
/// <param name="fileInfo"></param>
/// <param name="options"></param>
/// <summary>
/// Constructor with a FileInfo object to an existing file.
/// </summary>
/// <param name="fileInfo"></param>
/// <param name="options"></param>
internal TarArchive(FileInfo fileInfo, Options options)
: base(ArchiveType.Tar, fileInfo, options)
{
@@ -172,14 +174,16 @@ namespace SharpCompress.Archive.Tar
var oldStreamPos = stream.Position;
using(var entryStream = entry.OpenEntryStream())
using(var memoryStream = new MemoryStream())
using (var entryStream = entry.OpenEntryStream())
{
entryStream.TransferTo(memoryStream);
memoryStream.Position = 0;
var bytes = memoryStream.ToArray();
using (var memoryStream = new MemoryStream())
{
entryStream.TransferTo(memoryStream);
memoryStream.Position = 0;
var bytes = memoryStream.ToArray();
header.Name = ArchiveEncoding.Default.GetString(bytes, 0, bytes.Length).TrimNulls();
header.Name = ArchiveEncoding.Default.GetString(bytes, 0, bytes.Length).TrimNulls();
}
}
stream.Position = oldStreamPos;
@@ -198,7 +202,7 @@ namespace SharpCompress.Archive.Tar
}
protected override TarArchiveEntry CreateEntryInternal(string filePath, Stream source,
long size, DateTime? modified, bool closeStream)
long size, DateTime? modified, bool closeStream)
{
return new TarWritableArchiveEntry(this, source, CompressionType.Unknown, filePath, size, modified,
closeStream);

View File

@@ -19,12 +19,10 @@ namespace SharpCompress.Archive.Tar
}
#region IArchiveEntry Members
public IArchive Archive { get; private set; }
public bool IsComplete
{
get { return true; }
}
public IArchive Archive { get; }
public bool IsComplete { get { return true; } }
#endregion
}

View File

@@ -8,9 +8,6 @@ namespace SharpCompress.Archive.Tar
{
internal class TarWritableArchiveEntry : TarArchiveEntry, IWritableArchiveEntry
{
private readonly string path;
private readonly long size;
private readonly DateTime? lastModified;
private readonly bool closeStream;
private readonly Stream stream;
@@ -19,78 +16,36 @@ namespace SharpCompress.Archive.Tar
: base(archive, null, compressionType)
{
this.stream = stream;
this.path = path;
this.size = size;
this.lastModified = lastModified;
Key = path;
Size = size;
LastModifiedTime = lastModified;
this.closeStream = closeStream;
}
public override long Crc
{
get { return 0; }
}
public override long Crc { get { return 0; } }
public override string Key
{
get { return path; }
}
public override string Key { get; }
public override long CompressedSize
{
get { return 0; }
}
public override long CompressedSize { get { return 0; } }
public override long Size
{
get { return size; }
}
public override long Size { get; }
public override DateTime? LastModifiedTime
{
get { return lastModified; }
}
public override DateTime? LastModifiedTime { get; }
public override DateTime? CreatedTime
{
get { return null; }
}
public override DateTime? CreatedTime { get { return null; } }
public override DateTime? LastAccessedTime
{
get { return null; }
}
public override DateTime? LastAccessedTime { get { return null; } }
public override DateTime? ArchivedTime
{
get { return null; }
}
public override DateTime? ArchivedTime { get { return null; } }
public override bool IsEncrypted
{
get { return false; }
}
public override bool IsEncrypted { get { return false; } }
public override bool IsDirectory
{
get { return false; }
}
public override bool IsDirectory { get { return false; } }
public override bool IsSplit
{
get { return false; }
}
public override bool IsSplit { get { return false; } }
internal override IEnumerable<FilePart> Parts
{
get { throw new NotImplementedException(); }
}
Stream IWritableArchiveEntry.Stream
{
get
{
return stream;
}
}
internal override IEnumerable<FilePart> Parts { get { throw new NotImplementedException(); } }
Stream IWritableArchiveEntry.Stream { get { return stream; } }
public override Stream OpenEntryStream()
{

View File

@@ -23,11 +23,12 @@ namespace SharpCompress.Archive.Zip
public CompressionLevel DeflateCompressionLevel { get; set; }
#if !NO_FILE
/// <summary>
/// Constructor expects a filepath to an existing file.
/// </summary>
/// <param name="filePath"></param>
/// <param name="password"></param>
/// <summary>
/// Constructor expects a filepath to an existing file.
/// </summary>
/// <param name="filePath"></param>
/// <param name="password"></param>
public static ZipArchive Open(string filePath, string password = null)
{
return Open(filePath, Options.None, password);
@@ -121,7 +122,7 @@ namespace SharpCompress.Archive.Zip
{
return false;
}
return Enum.IsDefined(typeof (ZipHeaderType), header.ZipHeaderType);
return Enum.IsDefined(typeof(ZipHeaderType), header.ZipHeaderType);
}
catch (CryptographicException)
{
@@ -134,12 +135,13 @@ namespace SharpCompress.Archive.Zip
}
#if !NO_FILE
/// <summary>
/// Constructor with a FileInfo object to an existing file.
/// </summary>
/// <param name="fileInfo"></param>
/// <param name="options"></param>
/// <param name="password"></param>
/// <summary>
/// Constructor with a FileInfo object to an existing file.
/// </summary>
/// <param name="fileInfo"></param>
/// <param name="options"></param>
/// <param name="password"></param>
internal ZipArchive(FileInfo fileInfo, Options options, string password = null)
: base(ArchiveType.Zip, fileInfo, options)
{
@@ -189,19 +191,19 @@ namespace SharpCompress.Archive.Zip
switch (h.ZipHeaderType)
{
case ZipHeaderType.DirectoryEntry:
{
yield return new ZipArchiveEntry(this,
new SeekableZipFilePart(headerFactory,
h as DirectoryEntryHeader,
stream));
}
{
yield return new ZipArchiveEntry(this,
new SeekableZipFilePart(headerFactory,
h as DirectoryEntryHeader,
stream));
}
break;
case ZipHeaderType.DirectoryEnd:
{
byte[] bytes = (h as DirectoryEndHeader).Comment;
volume.Comment = ArchiveEncoding.Default.GetString(bytes, 0, bytes.Length);
yield break;
}
{
byte[] bytes = (h as DirectoryEndHeader).Comment;
volume.Comment = ArchiveEncoding.Default.GetString(bytes, 0, bytes.Length);
yield break;
}
}
}
}
@@ -225,7 +227,7 @@ namespace SharpCompress.Archive.Zip
}
protected override ZipArchiveEntry CreateEntryInternal(string filePath, Stream source, long size, DateTime? modified,
bool closeStream)
bool closeStream)
{
return new ZipWritableArchiveEntry(this, source, filePath, size, modified, closeStream);
}

View File

@@ -19,18 +19,12 @@ namespace SharpCompress.Archive.Zip
#region IArchiveEntry Members
public IArchive Archive { get; private set; }
public IArchive Archive { get; }
public bool IsComplete
{
get { return true; }
}
public bool IsComplete { get { return true; } }
#endregion
public string Comment
{
get { return (Parts.Single() as SeekableZipFilePart).Comment; }
}
public string Comment { get { return (Parts.Single() as SeekableZipFilePart).Comment; } }
}
}

View File

@@ -8,9 +8,6 @@ namespace SharpCompress.Archive.Zip
{
internal class ZipWritableArchiveEntry : ZipArchiveEntry, IWritableArchiveEntry
{
private readonly string path;
private readonly long size;
private readonly DateTime? lastModified;
private readonly bool closeStream;
private readonly Stream stream;
private bool isDisposed;
@@ -20,79 +17,37 @@ namespace SharpCompress.Archive.Zip
: base(archive, null)
{
this.stream = stream;
this.path = path;
this.size = size;
this.lastModified = lastModified;
Key = path;
Size = size;
LastModifiedTime = lastModified;
this.closeStream = closeStream;
}
public override long Crc
{
get { return 0; }
}
public override long Crc { get { return 0; } }
public override string Key
{
get { return path; }
}
public override string Key { get; }
public override long CompressedSize
{
get { return 0; }
}
public override long CompressedSize { get { return 0; } }
public override long Size
{
get { return size; }
}
public override long Size { get; }
public override DateTime? LastModifiedTime
{
get { return lastModified; }
}
public override DateTime? LastModifiedTime { get; }
public override DateTime? CreatedTime
{
get { return null; }
}
public override DateTime? CreatedTime { get { return null; } }
public override DateTime? LastAccessedTime
{
get { return null; }
}
public override DateTime? LastAccessedTime { get { return null; } }
public override DateTime? ArchivedTime
{
get { return null; }
}
public override DateTime? ArchivedTime { get { return null; } }
public override bool IsEncrypted
{
get { return false; }
}
public override bool IsEncrypted { get { return false; } }
public override bool IsDirectory
{
get { return false; }
}
public override bool IsDirectory { get { return false; } }
public override bool IsSplit
{
get { return false; }
}
public override bool IsSplit { get { return false; } }
internal override IEnumerable<FilePart> Parts
{
get { throw new NotImplementedException(); }
}
internal override IEnumerable<FilePart> Parts { get { throw new NotImplementedException(); } }
Stream IWritableArchiveEntry.Stream
{
get
{
return stream;
}
}
Stream IWritableArchiveEntry.Stream { get { return stream; } }
public override Stream OpenEntryStream()
{

View File

@@ -2,12 +2,8 @@
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyTitle("SharpCompress")]
[assembly: AssemblyProduct("SharpCompress")]
[assembly: InternalsVisibleTo("SharpCompress.Test")]
[assembly: InternalsVisibleTo("SharpCompress.Test.Portable")]
[assembly: CLSCompliant(true)]
[assembly: CLSCompliant(true)]

View File

@@ -6,6 +6,6 @@
Zip,
Tar,
SevenZip,
GZip,
GZip
}
}

View File

@@ -24,7 +24,7 @@ namespace SharpCompress.Common
public static implicit operator CompressionInfo(CompressionType compressionType)
{
return new CompressionInfo() {Type = compressionType};
return new CompressionInfo {Type = compressionType};
}
}
}

View File

@@ -11,6 +11,6 @@
LZMA,
BCJ,
BCJ2,
Unknown,
Unknown
}
}

View File

@@ -70,16 +70,11 @@ namespace SharpCompress.Common
internal virtual void Close()
{
}
/// <summary>
/// Entry file attribute.
/// </summary>
public virtual int? Attrib
{
get { throw new NotImplementedException(); }
}
public virtual int? Attrib { get { throw new NotImplementedException(); } }
}
}

View File

@@ -6,14 +6,14 @@ namespace SharpCompress.Common
{
public class EntryStream : Stream
{
public IReader Reader { get; private set; }
private Stream stream;
public IReader Reader { get; }
private readonly Stream stream;
private bool completed;
private bool isDisposed;
internal EntryStream(IReader reader, Stream stream)
{
this.Reader = reader;
Reader = reader;
this.stream = stream;
}
@@ -44,36 +44,20 @@ namespace SharpCompress.Common
stream.Dispose();
}
public override bool CanRead
{
get { return true; }
}
public override bool CanRead { get { return true; } }
public override bool CanSeek
{
get { return false; }
}
public override bool CanSeek { get { return false; } }
public override bool CanWrite
{
get { return false; }
}
public override bool CanWrite { get { return false; } }
public override void Flush()
{
throw new NotSupportedException();
}
public override long Length
{
get { throw new NotSupportedException(); }
}
public override long Length { get { throw new NotSupportedException(); } }
public override long Position
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}
public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } }
public override int Read(byte[] buffer, int offset, int count)
{

View File

@@ -25,6 +25,6 @@ namespace SharpCompress.Common
/// <summary>
/// preserve windows file attributes
/// </summary>
PreserveAttributes = 1 << 3,
PreserveAttributes = 1 << 3
}
}

View File

@@ -48,7 +48,7 @@ namespace SharpCompress.Common
{
return ((bitField & flag) == flag);
}
/// <summary>
/// Returns true if the flag is set on the specified bit field.
/// Currently only works with 32-bit bitfields.
@@ -75,7 +75,6 @@ namespace SharpCompress.Common
return ((bitField & flag) == flag);
}
/// <summary>
/// Sets a bit-field to either on or off for the specified flag.
/// </summary>
@@ -83,9 +82,9 @@ namespace SharpCompress.Common
/// <param name="flag">Flag to change</param>
/// <param name="on">bool</param>
/// <returns>The flagged variable with the flag changed</returns>
public static long SetFlag(long bitField, long flag, bool @on)
public static long SetFlag(long bitField, long flag, bool on)
{
if (@on)
if (on)
{
return bitField | flag;
}
@@ -100,10 +99,10 @@ namespace SharpCompress.Common
/// <param name="flag">Flag to change</param>
/// <param name="on">bool</param>
/// <returns>The flagged variable with the flag changed</returns>
public static long SetFlag<T>(T bitField, T flag, bool @on)
public static long SetFlag<T>(T bitField, T flag, bool on)
where T : struct
{
return SetFlag(Convert.ToInt64(bitField), Convert.ToInt64(flag), @on);
return SetFlag(Convert.ToInt64(bitField), Convert.ToInt64(flag), on);
}
}
}

View File

@@ -13,70 +13,31 @@ namespace SharpCompress.Common.GZip
this.filePart = filePart;
}
public override CompressionType CompressionType
{
get { return CompressionType.GZip; }
}
public override CompressionType CompressionType { get { return CompressionType.GZip; } }
public override long Crc
{
get { return 0; }
}
public override long Crc { get { return 0; } }
public override string Key
{
get { return filePart.FilePartName; }
}
public override string Key { get { return filePart.FilePartName; } }
public override long CompressedSize
{
get { return 0; }
}
public override long CompressedSize { get { return 0; } }
public override long Size
{
get { return 0; }
}
public override long Size { get { return 0; } }
public override DateTime? LastModifiedTime
{
get { return filePart.DateModified; }
}
public override DateTime? LastModifiedTime { get { return filePart.DateModified; } }
public override DateTime? CreatedTime
{
get { return null; }
}
public override DateTime? CreatedTime { get { return null; } }
public override DateTime? LastAccessedTime
{
get { return null; }
}
public override DateTime? LastAccessedTime { get { return null; } }
public override DateTime? ArchivedTime
{
get { return null; }
}
public override DateTime? ArchivedTime { get { return null; } }
public override bool IsEncrypted
{
get { return false; }
}
public override bool IsEncrypted { get { return false; } }
public override bool IsDirectory
{
get { return false; }
}
public override bool IsDirectory { get { return false; } }
public override bool IsSplit
{
get { return false; }
}
public override bool IsSplit { get { return false; } }
internal override IEnumerable<FilePart> Parts
{
get { return filePart.AsEnumerable<FilePart>(); }
}
internal override IEnumerable<FilePart> Parts { get { return filePart.AsEnumerable<FilePart>(); } }
internal static IEnumerable<GZipEntry> GetEntries(Stream stream)
{

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using SharpCompress.Common.Tar.Headers;
using SharpCompress.Compressor;
@@ -20,10 +21,7 @@ namespace SharpCompress.Common.GZip
internal DateTime? DateModified { get; private set; }
internal override string FilePartName
{
get { return name; }
}
internal override string FilePartName { get { return name; } }
internal override Stream GetCompressedStream()
{
@@ -43,13 +41,19 @@ namespace SharpCompress.Common.GZip
// workitem 8501: handle edge case (decompress empty stream)
if (n == 0)
{
return;
}
if (n != 10)
{
throw new ZlibException("Not a valid GZIP stream.");
}
if (header[0] != 0x1F || header[1] != 0x8B || header[2] != 8)
{
throw new ZlibException("Bad GZIP header.");
}
Int32 timet = DataConverter.LittleEndian.GetInt32(header, 4);
DateModified = TarHeader.Epoch.AddSeconds(timet);
@@ -58,7 +62,7 @@ namespace SharpCompress.Common.GZip
// read and discard extra field
n = stream.Read(header, 0, 2); // 2-byte length field
Int16 extraLength = (Int16) (header[0] + header[1]*256);
Int16 extraLength = (Int16)(header[0] + header[1] * 256);
byte[] extra = new byte[extraLength];
n = stream.Read(extra, 0, extra.Length);
if (n != extraLength)
@@ -67,18 +71,23 @@ namespace SharpCompress.Common.GZip
}
}
if ((header[3] & 0x08) == 0x08)
{
name = ReadZeroTerminatedString(stream);
}
if ((header[3] & 0x10) == 0x010)
{
ReadZeroTerminatedString(stream);
}
if ((header[3] & 0x02) == 0x02)
{
stream.ReadByte(); // CRC16, ignore
}
}
private static string ReadZeroTerminatedString(Stream stream)
{
byte[] buf1 = new byte[1];
var list = new System.Collections.Generic.List<byte>();
var list = new List<byte>();
bool done = false;
do
{
@@ -96,7 +105,8 @@ namespace SharpCompress.Common.GZip
{
list.Add(buf1[0]);
}
} while (!done);
}
while (!done);
byte[] a = list.ToArray();
return ArchiveEncoding.Default.GetString(a, 0, a.Length);
}

View File

@@ -16,14 +16,8 @@ namespace SharpCompress.Common.GZip
}
#endif
public override bool IsFirstVolume
{
get { return true; }
}
public override bool IsFirstVolume { get { return true; } }
public override bool IsMultiVolume
{
get { return true; }
}
public override bool IsMultiVolume { get { return true; } }
}
}

View File

@@ -1,4 +1,5 @@
#if !NO_FILE
#if !NO_FILE
using System.IO;
namespace SharpCompress.Common
@@ -46,4 +47,4 @@ namespace SharpCompress.Common
}
}
}
#endif
#endif

View File

@@ -1,4 +1,5 @@
using System;
#if !NO_FILE
using System.IO;
#endif

View File

@@ -18,6 +18,6 @@ namespace SharpCompress.Common
/// <summary>
/// Look for RarArchive (Check for self-extracting archives or cases where RarArchive isn't at the start of the file)
/// </summary>
LookForHeader = 2,
LookForHeader = 2
}
}

View File

@@ -17,10 +17,7 @@ namespace SharpCompress.Common.Rar.Headers
}
}
internal ArchiveFlags ArchiveHeaderFlags
{
get { return (ArchiveFlags) base.Flags; }
}
internal ArchiveFlags ArchiveHeaderFlags { get { return (ArchiveFlags)Flags; } }
internal short HighPosAv { get; private set; }
@@ -28,9 +25,6 @@ namespace SharpCompress.Common.Rar.Headers
internal byte EncryptionVersion { get; private set; }
public bool HasPassword
{
get { return ArchiveHeaderFlags.HasFlag(ArchiveFlags.PASSWORD); }
}
public bool HasPassword { get { return ArchiveHeaderFlags.HasFlag(ArchiveFlags.PASSWORD); } }
}
}

View File

@@ -16,10 +16,7 @@ namespace SharpCompress.Common.Rar.Headers
}
}
internal EndArchiveFlags EndArchiveFlags
{
get { return (EndArchiveFlags) base.Flags; }
}
internal EndArchiveFlags EndArchiveFlags { get { return (EndArchiveFlags)Flags; } }
internal int? ArchiveCRC { get; private set; }

View File

@@ -52,50 +52,50 @@ namespace SharpCompress.Common.Rar.Headers
switch (HeaderType)
{
case HeaderType.FileHeader:
{
if (FileFlags.HasFlag(FileFlags.UNICODE))
{
if (FileFlags.HasFlag(FileFlags.UNICODE))
int length = 0;
while (length < fileNameBytes.Length
&& fileNameBytes[length] != 0)
{
int length = 0;
while (length < fileNameBytes.Length
&& fileNameBytes[length] != 0)
{
length++;
}
if (length != nameSize)
{
length++;
FileName = FileNameDecoder.Decode(fileNameBytes, length);
}
else
{
FileName = DecodeDefault(fileNameBytes);
}
length++;
}
if (length != nameSize)
{
length++;
FileName = FileNameDecoder.Decode(fileNameBytes, length);
}
else
{
FileName = DecodeDefault(fileNameBytes);
}
FileName = ConvertPath(FileName, HostOS);
}
else
{
FileName = DecodeDefault(fileNameBytes);
}
FileName = ConvertPath(FileName, HostOS);
}
break;
case HeaderType.NewSubHeader:
{
int datasize = HeaderSize - NEWLHD_SIZE - nameSize;
if (FileFlags.HasFlag(FileFlags.SALT))
{
int datasize = HeaderSize - NEWLHD_SIZE - nameSize;
if (FileFlags.HasFlag(FileFlags.SALT))
{
datasize -= SALT_SIZE;
}
if (datasize > 0)
{
SubData = reader.ReadBytes(datasize);
}
if (NewSubHeaderType.SUBHEAD_TYPE_RR.Equals(fileNameBytes))
{
RecoverySectors = SubData[8] + (SubData[9] << 8)
+ (SubData[10] << 16) + (SubData[11] << 24);
}
datasize -= SALT_SIZE;
}
if (datasize > 0)
{
SubData = reader.ReadBytes(datasize);
}
if (NewSubHeaderType.SUBHEAD_TYPE_RR.Equals(fileNameBytes))
{
RecoverySectors = SubData[8] + (SubData[9] << 8)
+ (SubData[10] << 16) + (SubData[11] << 24);
}
}
break;
}
@@ -155,6 +155,7 @@ namespace SharpCompress.Common.Rar.Headers
byte b = reader.ReadByte();
nanosecondHundreds |= (((uint)b) << ((j + 3 - count) * 8));
}
//10^-7 to 10^-3
return time.Value.AddMilliseconds(nanosecondHundreds * Math.Pow(10, -4));
}
@@ -207,10 +208,7 @@ namespace SharpCompress.Common.Rar.Headers
internal int FileAttributes { get; private set; }
internal FileFlags FileFlags
{
get { return (FileFlags)base.Flags; }
}
internal FileFlags FileFlags { get { return (FileFlags)Flags; } }
internal long CompressedSize { get; private set; }
internal long UncompressedSize { get; private set; }

View File

@@ -32,19 +32,19 @@ namespace SharpCompress.Common.Rar.Headers
switch (flags >> 6)
{
case 0:
buf.Append((char) (GetChar(name, encPos++)));
buf.Append((char)(GetChar(name, encPos++)));
++decPos;
break;
case 1:
buf.Append((char) (GetChar(name, encPos++) + (highByte << 8)));
buf.Append((char)(GetChar(name, encPos++) + (highByte << 8)));
++decPos;
break;
case 2:
low = GetChar(name, encPos);
high = GetChar(name, encPos + 1);
buf.Append((char) ((high << 8) + low));
buf.Append((char)((high << 8) + low));
++decPos;
encPos += 2;
break;
@@ -57,14 +57,14 @@ namespace SharpCompress.Common.Rar.Headers
for (length = (length & 0x7f) + 2; length > 0 && decPos < name.Length; length--, decPos++)
{
low = (GetChar(name, decPos) + correction) & 0xff;
buf.Append((char) ((highByte << 8) + low));
buf.Append((char)((highByte << 8) + low));
}
}
else
{
for (length += 2; length > 0 && decPos < name.Length; length--, decPos++)
{
buf.Append((char) (GetChar(name, decPos)));
buf.Append((char)(GetChar(name, decPos)));
}
}
break;

View File

@@ -13,12 +13,12 @@ namespace SharpCompress.Common.Rar.Headers
ProtectHeader = 0x78,
SignHeader = 0x79,
NewSubHeader = 0x7a,
EndArchiveHeader = 0x7b,
EndArchiveHeader = 0x7b
}
internal enum HeaderFlags : short
{
LONG_BLOCK = -0x8000,
LONG_BLOCK = -0x8000
}
[Flags]
@@ -33,7 +33,7 @@ namespace SharpCompress.Common.Rar.Headers
PROTECT = 0x0040,
PASSWORD = 0x0080,
FIRSTVOLUME = 0x0100,
ENCRYPTVER = 0x0200,
ENCRYPTVER = 0x0200
}
internal enum HostOS
@@ -70,16 +70,15 @@ namespace SharpCompress.Common.Rar.Headers
SALT = 0x0400,
VERSION = 0x0800,
EXTTIME = 0x1000,
EXTFLAGS = 0x2000,
EXTFLAGS = 0x2000
}
[Flags]
internal enum EndArchiveFlags
{
EARC_NEXT_VOLUME = 0x0001,
EARC_DATACRC = 0x0002,
EARC_REVSPACE = 0x0004,
EARC_VOLNUMBER = 0x0008,
EARC_VOLNUMBER = 0x0008
}
}

View File

@@ -20,14 +20,14 @@ namespace SharpCompress.Common.Rar.Headers
//internal static final NewSubHeaderType SUBHEAD_TYPE_BEOSEA = new NewSubHeaderType(new byte[]{'E','A','B','E'});
private byte[] bytes;
private readonly byte[] bytes;
private NewSubHeaderType(params char[] chars)
{
bytes = new byte[chars.Length];
for (int i = 0; i < chars.Length; ++i)
{
bytes[i] = (byte) chars[i];
bytes[i] = (byte)chars[i];
}
}

View File

@@ -19,4 +19,4 @@ namespace SharpCompress.Common.Rar.Headers
internal uint TotalBlocks { get; private set; }
internal byte[] Mark { get; private set; }
}
}
}

View File

@@ -35,6 +35,7 @@ namespace SharpCompress.Common.Rar.Headers
return null;
}
}
protected virtual void ReadFromReader(MarkingBinaryReader reader)
{
HeadCRC = reader.ReadInt16();

View File

@@ -16,11 +16,11 @@ namespace SharpCompress.Common.Rar.Headers
Password = password;
}
private Options Options { get; set; }
private Options Options { get; }
public string Password { get; private set; }
internal StreamingMode StreamingMode { get; private set; }
internal StreamingMode StreamingMode { get; }
internal bool IsEncrypted { get; private set; }
internal IEnumerable<RarHeader> ReadHeaders(Stream stream)
{
if (Options.HasFlag(Options.LookForHeader))
@@ -114,7 +114,6 @@ namespace SharpCompress.Common.Rar.Headers
return rewindableStream;
}
private RarHeader ReadNextHeader(Stream stream)
{
#if !NO_CRYPTO
@@ -143,109 +142,109 @@ namespace SharpCompress.Common.Rar.Headers
switch (header.HeaderType)
{
case HeaderType.ArchiveHeader:
{
var ah = header.PromoteHeader<ArchiveHeader>(reader);
IsEncrypted = ah.HasPassword;
return ah;
}
{
var ah = header.PromoteHeader<ArchiveHeader>(reader);
IsEncrypted = ah.HasPassword;
return ah;
}
case HeaderType.MarkHeader:
{
return header.PromoteHeader<MarkHeader>(reader);
}
{
return header.PromoteHeader<MarkHeader>(reader);
}
case HeaderType.ProtectHeader:
{
ProtectHeader ph = header.PromoteHeader<ProtectHeader>(reader);
// skip the recovery record data, we do not use it.
switch (StreamingMode)
{
case StreamingMode.Seekable:
{
reader.BaseStream.Position += ph.DataSize;
}
break;
case StreamingMode.Streaming:
{
reader.BaseStream.Skip(ph.DataSize);
}
break;
default:
{
throw new InvalidFormatException("Invalid StreamingMode");
}
}
{
ProtectHeader ph = header.PromoteHeader<ProtectHeader>(reader);
return ph;
// skip the recovery record data, we do not use it.
switch (StreamingMode)
{
case StreamingMode.Seekable:
{
reader.BaseStream.Position += ph.DataSize;
}
break;
case StreamingMode.Streaming:
{
reader.BaseStream.Skip(ph.DataSize);
}
break;
default:
{
throw new InvalidFormatException("Invalid StreamingMode");
}
}
return ph;
}
case HeaderType.NewSubHeader:
{
FileHeader fh = header.PromoteHeader<FileHeader>(reader);
switch (StreamingMode)
{
FileHeader fh = header.PromoteHeader<FileHeader>(reader);
switch (StreamingMode)
case StreamingMode.Seekable:
{
case StreamingMode.Seekable:
{
fh.DataStartPosition = reader.BaseStream.Position;
reader.BaseStream.Position += fh.CompressedSize;
}
break;
case StreamingMode.Streaming:
{
//skip the data because it's useless?
reader.BaseStream.Skip(fh.CompressedSize);
}
break;
default:
{
throw new InvalidFormatException("Invalid StreamingMode");
}
fh.DataStartPosition = reader.BaseStream.Position;
reader.BaseStream.Position += fh.CompressedSize;
}
return fh;
}
case HeaderType.FileHeader:
{
FileHeader fh = header.PromoteHeader<FileHeader>(reader);
switch (StreamingMode)
break;
case StreamingMode.Streaming:
{
case StreamingMode.Seekable:
{
fh.DataStartPosition = reader.BaseStream.Position;
reader.BaseStream.Position += fh.CompressedSize;
}
break;
case StreamingMode.Streaming:
{
var ms = new ReadOnlySubStream(reader.BaseStream, fh.CompressedSize);
if (fh.Salt == null)
{
fh.PackedStream = ms;
}
else
{
//skip the data because it's useless?
reader.BaseStream.Skip(fh.CompressedSize);
}
break;
default:
{
throw new InvalidFormatException("Invalid StreamingMode");
}
}
return fh;
}
case HeaderType.FileHeader:
{
FileHeader fh = header.PromoteHeader<FileHeader>(reader);
switch (StreamingMode)
{
case StreamingMode.Seekable:
{
fh.DataStartPosition = reader.BaseStream.Position;
reader.BaseStream.Position += fh.CompressedSize;
}
break;
case StreamingMode.Streaming:
{
var ms = new ReadOnlySubStream(reader.BaseStream, fh.CompressedSize);
if (fh.Salt == null)
{
fh.PackedStream = ms;
}
else
{
#if !NO_CRYPTO
fh.PackedStream = new RarCryptoWrapper(ms, Password, fh.Salt);
#else
throw new NotSupportedException("RarCrypto not supported");
throw new NotSupportedException("RarCrypto not supported");
#endif
}
}
break;
default:
{
throw new InvalidFormatException("Invalid StreamingMode");
}
}
}
break;
default:
{
throw new InvalidFormatException("Invalid StreamingMode");
}
return fh;
}
return fh;
}
case HeaderType.EndArchiveHeader:
{
return header.PromoteHeader<EndArchiveHeader>(reader);
}
{
return header.PromoteHeader<EndArchiveHeader>(reader);
}
default:
{
throw new InvalidFormatException("Invalid Rar Header: " + header.HeaderType.ToString());
}
{
throw new InvalidFormatException("Invalid Rar Header: " + header.HeaderType);
}
}
}
}

View File

@@ -1,4 +1,5 @@
#if !NO_CRYPTO
#if !NO_CRYPTO
using System.Collections.Generic;
using System.IO;
using SharpCompress.IO;

View File

@@ -1,3 +1,4 @@
#if !NO_CRYPTO
using System;
using System.Collections.Generic;

View File

@@ -10,71 +10,44 @@ namespace SharpCompress.Common.Rar
/// <summary>
/// The File's 32 bit CRC Hash
/// </summary>
public override long Crc
{
get { return FileHeader.FileCRC; }
}
public override long Crc { get { return FileHeader.FileCRC; } }
/// <summary>
/// The path of the file internal to the Rar Archive.
/// </summary>
public override string Key
{
get { return FileHeader.FileName; }
}
public override string Key { get { return FileHeader.FileName; } }
/// <summary>
/// The entry last modified time in the archive, if recorded
/// </summary>
public override DateTime? LastModifiedTime
{
get { return FileHeader.FileLastModifiedTime; }
}
public override DateTime? LastModifiedTime { get { return FileHeader.FileLastModifiedTime; } }
/// <summary>
/// The entry create time in the archive, if recorded
/// </summary>
public override DateTime? CreatedTime
{
get { return FileHeader.FileCreatedTime; }
}
public override DateTime? CreatedTime { get { return FileHeader.FileCreatedTime; } }
/// <summary>
/// The entry last accessed time in the archive, if recorded
/// </summary>
public override DateTime? LastAccessedTime
{
get { return FileHeader.FileLastAccessedTime; }
}
public override DateTime? LastAccessedTime { get { return FileHeader.FileLastAccessedTime; } }
/// <summary>
/// The entry time whend archived, if recorded
/// </summary>
public override DateTime? ArchivedTime
{
get { return FileHeader.FileArchivedTime; }
}
public override DateTime? ArchivedTime { get { return FileHeader.FileArchivedTime; } }
/// <summary>
/// Entry is password protected and encrypted and cannot be extracted.
/// </summary>
public override bool IsEncrypted
{
get { return FileHeader.FileFlags.HasFlag(FileFlags.PASSWORD); }
}
public override bool IsEncrypted { get { return FileHeader.FileFlags.HasFlag(FileFlags.PASSWORD); } }
/// <summary>
/// Entry is password protected and encrypted and cannot be extracted.
/// </summary>
public override bool IsDirectory
{
get { return FileHeader.FileFlags.HasFlag(FileFlags.DIRECTORY); }
}
public override bool IsDirectory { get { return FileHeader.FileFlags.HasFlag(FileFlags.DIRECTORY); } }
public override bool IsSplit
{
get { return FileHeader.FileFlags.HasFlag(FileFlags.SPLIT_AFTER); }
}
public override bool IsSplit { get { return FileHeader.FileFlags.HasFlag(FileFlags.SPLIT_AFTER); } }
public override string ToString()
{

View File

@@ -1,4 +1,5 @@
#if !NO_CRYPTO
#if !NO_CRYPTO
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -13,7 +13,7 @@ namespace SharpCompress.Common.Rar
public abstract class RarVolume : Volume
{
private readonly RarHeaderFactory headerFactory;
internal RarVolume(StreamingMode mode, Stream stream, string password, Options options)
: base(stream, options)
{
@@ -23,10 +23,7 @@ namespace SharpCompress.Common.Rar
internal string Password { get; private set; }
internal StreamingMode Mode
{
get { return headerFactory.StreamingMode; }
}
internal StreamingMode Mode { get { return headerFactory.StreamingMode; } }
internal abstract IEnumerable<RarFilePart> ReadFileParts();
@@ -35,26 +32,26 @@ namespace SharpCompress.Common.Rar
internal IEnumerable<RarFilePart> GetVolumeFileParts()
{
MarkHeader previousMarkHeader = null;
foreach (RarHeader header in headerFactory.ReadHeaders(this.Stream))
foreach (RarHeader header in headerFactory.ReadHeaders(Stream))
{
switch (header.HeaderType)
{
case HeaderType.ArchiveHeader:
{
ArchiveHeader = header as ArchiveHeader;
}
{
ArchiveHeader = header as ArchiveHeader;
}
break;
case HeaderType.MarkHeader:
{
previousMarkHeader = header as MarkHeader;
}
{
previousMarkHeader = header as MarkHeader;
}
break;
case HeaderType.FileHeader:
{
FileHeader fh = header as FileHeader;
RarFilePart fp = CreateFilePart(fh, previousMarkHeader);
yield return fp;
}
{
FileHeader fh = header as FileHeader;
RarFilePart fp = CreateFilePart(fh, previousMarkHeader);
yield return fp;
}
break;
}
}
@@ -70,6 +67,7 @@ namespace SharpCompress.Common.Rar
{
throw new InvalidOperationException("ArchiveHeader should never been null in a streaming read.");
}
//we only want to load the archive header to avoid overhead but have to do the nasty thing and reset the stream
GetVolumeFileParts().First();
Stream.Position = 0;

View File

@@ -8,6 +8,7 @@ namespace SharpCompress.Common
{
Item = entry;
}
public T Item { get; private set; }
}
}
}

View File

@@ -80,15 +80,19 @@ namespace SharpCompress.Common.SevenZip
{
// v3.13 incorrectly worked with empty folders
// v4.07: Loop for skipping empty folders
for (; ; )
for (;;)
{
if (folderIndex >= Folders.Count)
{
throw new InvalidOperationException();
}
FolderStartFileIndex.Add(i); // check it
if (NumUnpackStreamsVector[folderIndex] != 0)
{
break;
}
folderIndex++;
}
@@ -97,7 +101,9 @@ namespace SharpCompress.Common.SevenZip
FileIndexToFolderIndexMap.Add(folderIndex);
if (emptyStream)
{
continue;
}
indexInFolder++;
@@ -128,7 +134,9 @@ namespace SharpCompress.Common.SevenZip
long size = 0;
for (int i = 0; i < folder.PackStreams.Count; i++)
{
size += PackSizes[packStreamIndex + i];
}
return size;
}
@@ -139,7 +147,9 @@ namespace SharpCompress.Common.SevenZip
long folderStartPackPos = GetFolderStreamPos(folder, 0);
List<long> packSizes = new List<long>();
for (int j = 0; j < folder.PackStreams.Count; j++)
{
packSizes.Add(PackSizes[packStreamIndex + j]);
}
return DecoderStreamHelper.CreateDecoderStream(stream, folderStartPackPos, packSizes.ToArray(), folder, pw);
}
@@ -153,8 +163,12 @@ namespace SharpCompress.Common.SevenZip
{
int folderIndex = FileIndexToFolderIndexMap[fileIndex];
if (folderIndex != -1)
{
if (FolderStartFileIndex[folderIndex] == fileIndex)
{
return GetFolderFullPackSize(folderIndex);
}
}
return 0;
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using SharpCompress.Compressor.LZMA;
@@ -17,7 +18,7 @@ namespace SharpCompress.Common.SevenZip
internal long _streamEnding;
internal byte[] _header;
private Dictionary<int, Stream> _cachedStreams = new Dictionary<int, Stream>();
private readonly Dictionary<int, Stream> _cachedStreams = new Dictionary<int, Stream>();
internal void AddByteStream(byte[] buffer, int offset, int length)
{
@@ -66,7 +67,9 @@ namespace SharpCompress.Common.SevenZip
{
ulong id = _currentReader.ReadNumber();
if (id > 25)
{
return null;
}
#if DEBUG
Log.WriteLine("ReadId: {0}", (BlockType)id);
#endif
@@ -85,13 +88,17 @@ namespace SharpCompress.Common.SevenZip
private void WaitAttribute(BlockType attribute)
{
for (; ; )
for (;;)
{
BlockType? type = ReadId();
if (type == attribute)
{
return;
}
if (type == BlockType.End)
{
throw new InvalidOperationException();
}
SkipData();
}
}
@@ -99,7 +106,9 @@ namespace SharpCompress.Common.SevenZip
private void ReadArchiveProperties()
{
while (ReadId() != BlockType.End)
{
SkipData();
}
}
#endregion
@@ -122,7 +131,9 @@ namespace SharpCompress.Common.SevenZip
}
if ((data & mask) != 0)
{
bits.SetBit(i);
}
mask >>= 1;
}
@@ -134,7 +145,9 @@ namespace SharpCompress.Common.SevenZip
{
byte allTrue = ReadByte();
if (allTrue != 0)
{
return new BitVector(length, true);
}
return ReadBitVector(length);
}
@@ -150,9 +163,13 @@ namespace SharpCompress.Common.SevenZip
for (int i = 0; i < numFiles; i++)
{
if (defined[i])
{
action(i, checked((long)ReadUInt64()));
}
else
{
action(i, null);
}
}
}
}
@@ -166,9 +183,10 @@ namespace SharpCompress.Common.SevenZip
private DateTime? TranslateTime(long? time)
{
if (time.HasValue)
{
return TranslateTime(time.Value);
else
return null;
}
return null;
}
private void ReadDateTimeVector(List<byte[]> dataVector, int numFiles, Action<int, DateTime?> action)
@@ -185,9 +203,13 @@ namespace SharpCompress.Common.SevenZip
for (int i = 0; i < numFiles; i++)
{
if (boolVector[i])
{
action(i, ReadUInt32());
}
else
{
action(i, null);
}
}
}
}
@@ -230,10 +252,14 @@ namespace SharpCompress.Common.SevenZip
Log.WriteLine("MethodId: " + String.Join("", Enumerable.Range(0, idSize).Select(x => longID[x].ToString("x2")).ToArray()));
#endif
if (idSize > 8)
{
throw new NotSupportedException();
}
ulong id = 0;
for (int j = 0; j < idSize; j++)
{
id |= (ulong)longID[idSize - 1 - j] << (8 * j);
}
coder.MethodId = new CMethodId(id);
if ((mainByte & 0x10) != 0)
@@ -264,7 +290,9 @@ namespace SharpCompress.Common.SevenZip
}
if ((mainByte & 0x80) != 0)
{
throw new NotSupportedException();
}
numInStreams += coder.NumInStreams;
numOutStreams += coder.NumOutStreams;
@@ -298,9 +326,12 @@ namespace SharpCompress.Common.SevenZip
#endif
if (numInStreams < numBindPairs)
{
throw new NotSupportedException();
}
int numPackStreams = numInStreams - numBindPairs;
//folder.PackStreams.Reserve(numPackStreams);
if (numPackStreams == 1)
{
@@ -317,7 +348,9 @@ namespace SharpCompress.Common.SevenZip
}
if (folder.PackStreams.Count != 1)
{
throw new NotSupportedException();
}
}
else
{
@@ -417,11 +450,13 @@ namespace SharpCompress.Common.SevenZip
#endif
BlockType? type;
for (; ; )
for (;;)
{
type = ReadId();
if (type == BlockType.End)
{
break;
}
if (type == BlockType.CRC)
{
packCRCs = ReadHashDigests(numPackStreams);
@@ -434,7 +469,9 @@ namespace SharpCompress.Common.SevenZip
{
packCRCs = new List<uint?>(numPackStreams);
for (int i = 0; i < numPackStreams; i++)
{
packCRCs.Add(null);
}
}
}
finally
@@ -462,13 +499,14 @@ namespace SharpCompress.Common.SevenZip
using (CStreamSwitch streamSwitch = new CStreamSwitch())
{
streamSwitch.Set(this, dataVector);
//folders.Clear();
//folders.Reserve(numFolders);
folders = new List<CFolder>(numFolders);
int index = 0;
for (int i = 0; i < numFolders; i++)
{
var f = new CFolder { FirstPackStreamId = index };
var f = new CFolder {FirstPackStreamId = index};
folders.Add(f);
GetNextFolderItem(f);
index += f.PackStreams.Count;
@@ -499,17 +537,21 @@ namespace SharpCompress.Common.SevenZip
#endif
}
for (; ; )
for (;;)
{
BlockType? type = ReadId();
if (type == BlockType.End)
{
return;
}
if (type == BlockType.CRC)
{
List<uint?> crcs = ReadHashDigests(numFolders);
for (int i = 0; i < numFolders; i++)
{
folders[i].UnpackCRC = crcs[i];
}
continue;
}
@@ -536,7 +578,7 @@ namespace SharpCompress.Common.SevenZip
numUnpackStreamsInFolders = null;
BlockType? type;
for (; ; )
for (;;)
{
type = ReadId();
if (type == BlockType.NumUnpackStream)
@@ -559,9 +601,13 @@ namespace SharpCompress.Common.SevenZip
continue;
}
if (type == BlockType.CRC || type == BlockType.Size)
{
break;
}
if (type == BlockType.End)
{
break;
}
SkipData();
}
@@ -569,7 +615,9 @@ namespace SharpCompress.Common.SevenZip
{
numUnpackStreamsInFolders = new List<int>(folders.Count);
for (int i = 0; i < folders.Count; i++)
{
numUnpackStreamsInFolders.Add(1);
}
}
unpackSizes = new List<long>(folders.Count);
@@ -579,7 +627,9 @@ namespace SharpCompress.Common.SevenZip
// v4.07: we check that folder is empty
int numSubstreams = numUnpackStreamsInFolders[i];
if (numSubstreams == 0)
{
continue;
}
#if DEBUG
Log.Write("#{0} StreamSizes:", i);
#endif
@@ -602,7 +652,9 @@ namespace SharpCompress.Common.SevenZip
#endif
}
if (type == BlockType.Size)
{
type = ReadId();
}
int numDigests = 0;
int numDigestsTotal = 0;
@@ -610,13 +662,15 @@ namespace SharpCompress.Common.SevenZip
{
int numSubstreams = numUnpackStreamsInFolders[i];
if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)
{
numDigests += numSubstreams;
}
numDigestsTotal += numSubstreams;
}
digests = null;
for (; ; )
for (;;)
{
if (type == BlockType.CRC)
{
@@ -636,12 +690,16 @@ namespace SharpCompress.Common.SevenZip
else
{
for (int j = 0; j < numSubstreams; j++, digestIndex++)
{
digests.Add(digests2[digestIndex]);
}
}
}
if (digestIndex != numDigests || numDigestsTotal != digests.Count)
System.Diagnostics.Debugger.Break();
{
Debugger.Break();
}
}
else if (type == BlockType.End)
{
@@ -649,7 +707,9 @@ namespace SharpCompress.Common.SevenZip
{
digests = new List<uint?>(numDigestsTotal);
for (int i = 0; i < numDigestsTotal; i++)
{
digests.Add(null);
}
}
return;
}
@@ -693,7 +753,7 @@ namespace SharpCompress.Common.SevenZip
unpackSizes = null;
digests = null;
for (; ; )
for (;;)
{
switch (ReadId())
{
@@ -768,12 +828,18 @@ namespace SharpCompress.Common.SevenZip
byte[] data = new byte[unpackSize];
outStream.ReadExact(data, 0, data.Length);
if (outStream.ReadByte() >= 0)
{
throw new InvalidOperationException("Decoded stream is longer than expected.");
}
dataVector.Add(data);
if (folder.UnpackCRCDefined)
{
if (CRC.Finish(CRC.Update(CRC.kInitCRC, data, 0, unpackSize)) != folder.UnpackCRC)
{
throw new InvalidOperationException("Decoded stream does not match expected CRC.");
}
}
}
return dataVector;
}
@@ -842,10 +908,14 @@ namespace SharpCompress.Common.SevenZip
db.Files.Clear();
if (type == BlockType.End)
{
return;
}
if (type != BlockType.FilesInfo)
{
throw new InvalidOperationException();
}
int numFiles = ReadNum();
#if DEBUG
@@ -853,18 +923,22 @@ namespace SharpCompress.Common.SevenZip
#endif
db.Files = new List<CFileItem>(numFiles);
for (int i = 0; i < numFiles; i++)
{
db.Files.Add(new CFileItem());
}
BitVector emptyStreamVector = new BitVector(numFiles);
BitVector emptyFileVector = null;
BitVector antiFileVector = null;
int numEmptyStreams = 0;
for (; ; )
for (;;)
{
type = ReadId();
if (type == BlockType.End)
{
break;
}
long size = checked((long)ReadNumber()); // TODO: throw invalid data on negative
int oldPos = _currentReader.Offset;
@@ -894,32 +968,34 @@ namespace SharpCompress.Common.SevenZip
Log.Write("WinAttributes:");
#endif
ReadAttributeVector(dataVector, numFiles, delegate(int i, uint? attr)
{
// Some third party implementations established an unofficial extension
// of the 7z archive format by placing posix file attributes in the high
// bits of the windows file attributes. This makes use of the fact that
// the official implementation does not perform checks on this value.
//
// Newer versions of the official 7z GUI client will try to parse this
// extension, thus acknowledging the unofficial use of these bits.
//
// For us it is safe to just discard the upper bits if they are set and
// keep the windows attributes from the lower bits (which should be set
// properly even if posix file attributes are present, in order to be
// compatible with older 7z archive readers)
//
// Note that the 15th bit is used by some implementations to indicate
// presence of the extension, but not all implementations do that so
// we can't trust that bit and must ignore it.
//
if (attr.HasValue && (attr.Value >> 16) != 0)
{
// Some third party implementations established an unofficial extension
// of the 7z archive format by placing posix file attributes in the high
// bits of the windows file attributes. This makes use of the fact that
// the official implementation does not perform checks on this value.
//
// Newer versions of the official 7z GUI client will try to parse this
// extension, thus acknowledging the unofficial use of these bits.
//
// For us it is safe to just discard the upper bits if they are set and
// keep the windows attributes from the lower bits (which should be set
// properly even if posix file attributes are present, in order to be
// compatible with older 7z archive readers)
//
// Note that the 15th bit is used by some implementations to indicate
// presence of the extension, but not all implementations do that so
// we can't trust that bit and must ignore it.
//
if (attr.HasValue && (attr.Value >> 16) != 0)
attr = attr.Value & 0x7FFFu;
attr = attr.Value & 0x7FFFu;
}
db.Files[i].Attrib = attr;
db.Files[i].Attrib = attr;
#if DEBUG
Log.Write(" " + (attr.HasValue ? attr.Value.ToString("x8") : "n/a"));
Log.Write(" " + (attr.HasValue ? attr.Value.ToString("x8") : "n/a"));
#endif
});
});
#if DEBUG
Log.WriteLine();
#endif
@@ -958,7 +1034,9 @@ namespace SharpCompress.Common.SevenZip
#if DEBUG
Log.Write("EmptyFile: ");
for (int i = 0; i < numEmptyStreams; i++)
{
Log.Write(emptyFileVector[i] ? "x" : ".");
}
Log.WriteLine();
#endif
break;
@@ -967,7 +1045,9 @@ namespace SharpCompress.Common.SevenZip
#if DEBUG
Log.Write("Anti: ");
for (int i = 0; i < numEmptyStreams; i++)
{
Log.Write(antiFileVector[i] ? "x" : ".");
}
Log.WriteLine();
#endif
break;
@@ -976,12 +1056,12 @@ namespace SharpCompress.Common.SevenZip
Log.Write("StartPos:");
#endif
ReadNumberVector(dataVector, numFiles, delegate(int i, long? startPos)
{
db.Files[i].StartPos = startPos;
{
db.Files[i].StartPos = startPos;
#if DEBUG
Log.Write(" " + (startPos.HasValue ? startPos.Value.ToString() : "n/a"));
Log.Write(" " + (startPos.HasValue ? startPos.Value.ToString() : "n/a"));
#endif
});
});
#if DEBUG
Log.WriteLine();
#endif
@@ -991,12 +1071,12 @@ namespace SharpCompress.Common.SevenZip
Log.Write("CTime:");
#endif
ReadDateTimeVector(dataVector, numFiles, delegate(int i, DateTime? time)
{
db.Files[i].CTime = time;
{
db.Files[i].CTime = time;
#if DEBUG
Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a"));
Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a"));
#endif
});
});
#if DEBUG
Log.WriteLine();
#endif
@@ -1006,12 +1086,12 @@ namespace SharpCompress.Common.SevenZip
Log.Write("ATime:");
#endif
ReadDateTimeVector(dataVector, numFiles, delegate(int i, DateTime? time)
{
db.Files[i].ATime = time;
{
db.Files[i].ATime = time;
#if DEBUG
Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a"));
Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a"));
#endif
});
});
#if DEBUG
Log.WriteLine();
#endif
@@ -1021,12 +1101,12 @@ namespace SharpCompress.Common.SevenZip
Log.Write("MTime:");
#endif
ReadDateTimeVector(dataVector, numFiles, delegate(int i, DateTime? time)
{
db.Files[i].MTime = time;
{
db.Files[i].MTime = time;
#if DEBUG
Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a"));
Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a"));
#endif
});
});
#if DEBUG
Log.WriteLine();
#endif
@@ -1036,8 +1116,12 @@ namespace SharpCompress.Common.SevenZip
Log.Write("Dummy: " + size);
#endif
for (long j = 0; j < size; j++)
{
if (ReadByte() != 0)
{
throw new InvalidOperationException();
}
}
break;
default:
SkipData(size);
@@ -1047,7 +1131,9 @@ namespace SharpCompress.Common.SevenZip
// since 0.3 record sizes must be correct
bool checkRecordsSize = (db.MajorVersion > 0 || db.MinorVersion > 2);
if (checkRecordsSize && _currentReader.Offset - oldPos != size)
{
throw new InvalidOperationException();
}
}
int emptyFileIndex = 0;
@@ -1095,11 +1181,13 @@ namespace SharpCompress.Common.SevenZip
// TODO: Check Signature!
_header = new byte[0x20];
for (int offset = 0; offset < 0x20; )
for (int offset = 0; offset < 0x20;)
{
int delta = stream.Read(_header, offset, 0x20 - offset);
if (delta == 0)
{
throw new EndOfStreamException();
}
offset += delta;
}
@@ -1109,10 +1197,14 @@ namespace SharpCompress.Common.SevenZip
public void Close()
{
if (_stream != null)
{
_stream.Dispose();
}
foreach (var stream in _cachedStreams.Values)
{
stream.Dispose();
}
_cachedStreams.Clear();
}
@@ -1126,7 +1218,9 @@ namespace SharpCompress.Common.SevenZip
db.MinorVersion = _header[7];
if (db.MajorVersion != 0)
{
throw new InvalidOperationException();
}
uint crcFromArchive = DataReader.Get32(_header, 8);
long nextHeaderOffset = (long)DataReader.Get64(_header, 0xC);
@@ -1140,7 +1234,9 @@ namespace SharpCompress.Common.SevenZip
crc = CRC.Finish(crc);
if (crc != crcFromArchive)
{
throw new InvalidOperationException();
}
db.StartPositionAfterHeader = _streamOrigin + 0x20;
@@ -1151,12 +1247,15 @@ namespace SharpCompress.Common.SevenZip
return db;
}
if (nextHeaderOffset < 0 || nextHeaderSize < 0 || nextHeaderSize > Int32.MaxValue)
{
throw new InvalidOperationException();
}
if (nextHeaderOffset > _streamEnding - db.StartPositionAfterHeader)
{
throw new IndexOutOfRangeException();
}
_stream.Seek(nextHeaderOffset, SeekOrigin.Current);
@@ -1164,7 +1263,9 @@ namespace SharpCompress.Common.SevenZip
_stream.ReadExact(header, 0, header.Length);
if (CRC.Finish(CRC.Update(CRC.kInitCRC, header, 0, header.Length)) != nextHeaderCrc)
{
throw new InvalidOperationException();
}
using (CStreamSwitch streamSwitch = new CStreamSwitch())
{
@@ -1174,7 +1275,9 @@ namespace SharpCompress.Common.SevenZip
if (type != BlockType.Header)
{
if (type != BlockType.EncodedHeader)
{
throw new InvalidOperationException();
}
var dataVector = ReadAndDecodePackedStreams(db.StartPositionAfterHeader, pass);
@@ -1186,12 +1289,16 @@ namespace SharpCompress.Common.SevenZip
}
if (dataVector.Count != 1)
{
throw new InvalidOperationException();
}
streamSwitch.Set(this, dataVector[0]);
if (ReadId() != BlockType.Header)
{
throw new InvalidOperationException();
}
}
ReadHeader(db, pass);
@@ -1211,55 +1318,41 @@ namespace SharpCompress.Common.SevenZip
FileIndex = fileIndex;
FolderIndex = folderIndex;
if (fileIndex != -1)
{
ExtractStatuses.Add(true);
}
}
}
private class FolderUnpackStream : Stream
{
private ArchiveDatabase _db;
private int _startIndex;
private List<bool> _extractStatuses;
private readonly ArchiveDatabase _db;
private readonly int _startIndex;
private readonly List<bool> _extractStatuses;
public FolderUnpackStream(ArchiveDatabase db, int p, int startIndex, List<bool> list)
{
this._db = db;
this._startIndex = startIndex;
this._extractStatuses = list;
_db = db;
_startIndex = startIndex;
_extractStatuses = list;
}
#region Stream
public override bool CanRead
{
get { return true; }
}
public override bool CanRead { get { return true; } }
public override bool CanSeek
{
get { return false; }
}
public override bool CanSeek { get { return false; } }
public override bool CanWrite
{
get { return false; }
}
public override bool CanWrite { get { return false; } }
public override void Flush()
{
throw new NotSupportedException();
}
public override long Length
{
get { throw new NotSupportedException(); }
}
public override long Length { get { throw new NotSupportedException(); } }
public override long Position
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}
public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } }
public override int Read(byte[] buffer, int offset, int count)
{
@@ -1298,9 +1391,13 @@ namespace SharpCompress.Common.SevenZip
Log.WriteLine(_db.Files[index].Name);
#endif
if (_db.Files[index].CrcDefined)
{
_stream = new CrcCheckStream(_db.Files[index].Crc.Value);
}
else
{
_stream = new MemoryStream();
}
_rem = _db.Files[index].Size;
}
@@ -1312,7 +1409,9 @@ namespace SharpCompress.Common.SevenZip
{
int write = count;
if (write > _rem)
{
write = (int)_rem;
}
_stream.Write(buffer, offset, write);
count -= write;
_rem -= write;
@@ -1331,7 +1430,7 @@ namespace SharpCompress.Common.SevenZip
if (_currentIndex == _extractStatuses.Count)
{
// we support partial extracting
System.Diagnostics.Debugger.Break();
Debugger.Break();
throw new NotSupportedException();
}
OpenFile();
@@ -1352,7 +1451,9 @@ namespace SharpCompress.Common.SevenZip
long folderStartPackPos = _db.GetFolderStreamPos(folderInfo, 0);
List<long> packSizes = new List<long>();
for (int j = 0; j < folderInfo.PackStreams.Count; j++)
{
packSizes.Add(_db.PackSizes[packStreamIndex + j]);
}
s = DecoderStreamHelper.CreateDecoderStream(_stream, folderStartPackPos, packSizes.ToArray(), folderInfo,
pw);
@@ -1367,12 +1468,16 @@ namespace SharpCompress.Common.SevenZip
int numFilesInFolder = _db.NumUnpackStreamsVector[folderIndex];
int firstFileIndex = _db.FolderStartFileIndex[folderIndex];
if (firstFileIndex > fileIndex || fileIndex - firstFileIndex >= numFilesInFolder)
{
throw new InvalidOperationException();
}
int skipCount = fileIndex - firstFileIndex;
long skipSize = 0;
for (int i = 0; i < skipCount; i++)
{
skipSize += _db.Files[firstFileIndex + i].Size;
}
Stream s = GetCachedDecoderStream(_db, folderIndex, pw);
s.Position = skipSize;
@@ -1384,12 +1489,18 @@ namespace SharpCompress.Common.SevenZip
int numItems;
bool allFilesMode = (indices == null);
if (allFilesMode)
{
numItems = _db.Files.Count;
}
else
{
numItems = indices.Length;
}
if (numItems == 0)
{
return;
}
List<CExtractFolderInfo> extractFolderInfoVector = new List<CExtractFolderInfo>();
for (int i = 0; i < numItems; i++)
@@ -1404,27 +1515,37 @@ namespace SharpCompress.Common.SevenZip
}
if (extractFolderInfoVector.Count == 0 || folderIndex != extractFolderInfoVector.Last().FolderIndex)
{
extractFolderInfoVector.Add(new CExtractFolderInfo(-1, folderIndex));
}
CExtractFolderInfo efi = extractFolderInfoVector.Last();
int startIndex = _db.FolderStartFileIndex[folderIndex];
for (int index = efi.ExtractStatuses.Count; index <= fileIndex - startIndex; index++)
{
efi.ExtractStatuses.Add(index == fileIndex - startIndex);
}
}
foreach (CExtractFolderInfo efi in extractFolderInfoVector)
{
int startIndex;
if (efi.FileIndex != -1)
{
startIndex = efi.FileIndex;
}
else
{
startIndex = _db.FolderStartFileIndex[efi.FolderIndex];
}
var outStream = new FolderUnpackStream(_db, 0, startIndex, efi.ExtractStatuses);
if (efi.FileIndex != -1)
{
continue;
}
int folderIndex = efi.FolderIndex;
CFolder folderInfo = _db.Folders[folderIndex];
@@ -1434,18 +1555,22 @@ namespace SharpCompress.Common.SevenZip
List<long> packSizes = new List<long>();
for (int j = 0; j < folderInfo.PackStreams.Count; j++)
{
packSizes.Add(_db.PackSizes[packStreamIndex + j]);
}
// TODO: If the decoding fails the last file may be extracted incompletely. Delete it?
Stream s = DecoderStreamHelper.CreateDecoderStream(_stream, folderStartPackPos, packSizes.ToArray(),
folderInfo, pw);
byte[] buffer = new byte[4 << 10];
for (; ; )
for (;;)
{
int processed = s.Read(buffer, 0, buffer.Length);
if (processed == 0)
{
break;
}
outStream.Write(buffer, 0, processed);
}
}

View File

@@ -12,19 +12,13 @@ namespace SharpCompress.Common.SevenZip
public bool HasStream { get; internal set; }
public bool IsDir { get; internal set; }
public bool CrcDefined
{
get { return Crc != null; }
}
public bool CrcDefined { get { return Crc != null; } }
public bool AttribDefined
{
get { return Attrib != null; }
}
public bool AttribDefined { get { return Attrib != null; } }
public void SetAttrib(uint attrib)
{
this.Attrib = attrib;
Attrib = attrib;
}
public DateTime? CTime { get; internal set; }

View File

@@ -13,19 +13,22 @@ namespace SharpCompress.Common.SevenZip
internal List<long> UnpackSizes = new List<long>();
internal uint? UnpackCRC;
internal bool UnpackCRCDefined
{
get { return UnpackCRC != null; }
}
internal bool UnpackCRCDefined { get { return UnpackCRC != null; } }
public long GetUnpackSize()
{
if (UnpackSizes.Count == 0)
{
return 0;
}
for (int i = UnpackSizes.Count - 1; i >= 0; i--)
{
if (FindBindPairForOutStream(i) < 0)
{
return UnpackSizes[i];
}
}
throw new Exception();
}
@@ -34,7 +37,9 @@ namespace SharpCompress.Common.SevenZip
{
int count = 0;
for (int i = 0; i < Coders.Count; i++)
{
count += Coders[i].NumOutStreams;
}
return count;
}
@@ -42,8 +47,12 @@ namespace SharpCompress.Common.SevenZip
public int FindBindPairForInStream(int inStreamIndex)
{
for (int i = 0; i < BindPairs.Count; i++)
{
if (BindPairs[i].InIndex == inStreamIndex)
{
return i;
}
}
return -1;
}
@@ -51,8 +60,12 @@ namespace SharpCompress.Common.SevenZip
public int FindBindPairForOutStream(int outStreamIndex)
{
for (int i = 0; i < BindPairs.Count; i++)
{
if (BindPairs[i].OutIndex == outStreamIndex)
{
return i;
}
}
return -1;
}
@@ -60,8 +73,12 @@ namespace SharpCompress.Common.SevenZip
public int FindPackStreamArrayIndex(int inStreamIndex)
{
for (int i = 0; i < PackStreams.Count; i++)
{
if (PackStreams[i] == inStreamIndex)
{
return i;
}
}
return -1;
}
@@ -69,8 +86,12 @@ namespace SharpCompress.Common.SevenZip
public bool IsEncrypted()
{
for (int i = Coders.Count - 1; i >= 0; i--)
{
if (Coders[i].MethodId == CMethodId.kAES)
{
return true;
}
}
return false;
}
@@ -82,25 +103,39 @@ namespace SharpCompress.Common.SevenZip
const int kNumBindsMax = 32;
if (Coders.Count > kNumCodersMax || BindPairs.Count > kNumBindsMax)
{
return false;
}
{
var v = new BitVector(BindPairs.Count + PackStreams.Count);
for (int i = 0; i < BindPairs.Count; i++)
{
if (v.GetAndSet(BindPairs[i].InIndex))
{
return false;
}
}
for (int i = 0; i < PackStreams.Count; i++)
{
if (v.GetAndSet(PackStreams[i]))
{
return false;
}
}
}
{
var v = new BitVector(UnpackSizes.Count);
for (int i = 0; i < BindPairs.Count; i++)
{
if (v.GetAndSet(BindPairs[i].OutIndex))
{
return false;
}
}
}
uint[] mask = new uint[kMaskSize];
@@ -112,9 +147,13 @@ namespace SharpCompress.Common.SevenZip
{
CCoderInfo coder = Coders[i];
for (int j = 0; j < coder.NumInStreams; j++)
{
inStreamToCoder.Add(i);
}
for (int j = 0; j < coder.NumOutStreams; j++)
{
outStreamToCoder.Add(i);
}
}
for (int i = 0; i < BindPairs.Count; i++)
@@ -125,13 +164,23 @@ namespace SharpCompress.Common.SevenZip
}
for (int i = 0; i < kMaskSize; i++)
{
for (int j = 0; j < kMaskSize; j++)
{
if (((1u << j) & mask[i]) != 0)
{
mask[i] |= mask[j];
}
}
}
for (int i = 0; i < kMaskSize; i++)
{
if (((1u << i) & mask[i]) != 0)
{
return false;
}
}
return true;
}

View File

@@ -16,7 +16,7 @@
public CMethodId(ulong id)
{
this.Id = id;
Id = id;
}
public override int GetHashCode()
@@ -26,7 +26,7 @@
public override bool Equals(object obj)
{
return obj is CMethodId && (CMethodId) obj == this;
return obj is CMethodId && (CMethodId)obj == this;
}
public bool Equals(CMethodId other)
@@ -48,7 +48,9 @@
{
int bytes = 0;
for (ulong value = Id; value != 0; value >>= 8)
{
bytes++;
}
return bytes;
}
}

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using SharpCompress.Compressor.LZMA;
namespace SharpCompress.Common.SevenZip
@@ -47,7 +46,9 @@ namespace SharpCompress.Common.SevenZip
{
int dataIndex = archive.ReadNum();
if (dataIndex < 0 || dataIndex >= dataVector.Count)
{
throw new InvalidOperationException();
}
#if DEBUG
Log.WriteLine("[switch to stream {0}]", dataIndex);

View File

@@ -11,31 +11,30 @@ namespace SharpCompress.Common.SevenZip
public static uint Get32(byte[] buffer, int offset)
{
return (uint) buffer[offset]
+ ((uint) buffer[offset + 1] << 8)
+ ((uint) buffer[offset + 2] << 16)
+ ((uint) buffer[offset + 3] << 24);
return buffer[offset]
+ ((uint)buffer[offset + 1] << 8)
+ ((uint)buffer[offset + 2] << 16)
+ ((uint)buffer[offset + 3] << 24);
}
public static ulong Get64(byte[] buffer, int offset)
{
return (ulong) buffer[offset]
+ ((ulong) buffer[offset + 1] << 8)
+ ((ulong) buffer[offset + 2] << 16)
+ ((ulong) buffer[offset + 3] << 24)
+ ((ulong) buffer[offset + 4] << 32)
+ ((ulong) buffer[offset + 5] << 40)
+ ((ulong) buffer[offset + 6] << 48)
+ ((ulong) buffer[offset + 7] << 56);
return buffer[offset]
+ ((ulong)buffer[offset + 1] << 8)
+ ((ulong)buffer[offset + 2] << 16)
+ ((ulong)buffer[offset + 3] << 24)
+ ((ulong)buffer[offset + 4] << 32)
+ ((ulong)buffer[offset + 5] << 40)
+ ((ulong)buffer[offset + 6] << 48)
+ ((ulong)buffer[offset + 7] << 56);
}
#endregion
#region Variables
private byte[] _buffer;
private int _offset;
private int _ending;
private readonly byte[] _buffer;
private readonly int _ending;
#endregion
@@ -44,38 +43,43 @@ namespace SharpCompress.Common.SevenZip
public DataReader(byte[] buffer, int offset, int length)
{
_buffer = buffer;
_offset = offset;
Offset = offset;
_ending = offset + length;
}
public int Offset
{
get { return _offset; }
}
public int Offset { get; private set; }
public Byte ReadByte()
{
if (_offset >= _ending)
if (Offset >= _ending)
{
throw new EndOfStreamException();
}
return _buffer[_offset++];
return _buffer[Offset++];
}
public void ReadBytes(byte[] buffer, int offset, int length)
{
if (length > _ending - _offset)
if (length > _ending - Offset)
{
throw new EndOfStreamException();
}
while (length-- > 0)
buffer[offset++] = _buffer[_offset++];
{
buffer[offset++] = _buffer[Offset++];
}
}
public void SkipData(long size)
{
if (size > _ending - _offset)
if (size > _ending - Offset)
{
throw new EndOfStreamException();
}
_offset += (int) size;
Offset += (int)size;
#if DEBUG
Log.WriteLine("SkipData {0}", size);
#endif
@@ -83,15 +87,17 @@ namespace SharpCompress.Common.SevenZip
public void SkipData()
{
SkipData(checked((long) ReadNumber()));
SkipData(checked((long)ReadNumber()));
}
public ulong ReadNumber()
{
if (_offset >= _ending)
if (Offset >= _ending)
{
throw new EndOfStreamException();
}
byte firstByte = _buffer[_offset++];
byte firstByte = _buffer[Offset++];
byte mask = 0x80;
ulong value = 0;
@@ -100,14 +106,16 @@ namespace SharpCompress.Common.SevenZip
if ((firstByte & mask) == 0)
{
ulong highPart = firstByte & (mask - 1u);
value += highPart << (i*8);
value += highPart << (i * 8);
return value;
}
if (_offset >= _ending)
if (Offset >= _ending)
{
throw new EndOfStreamException();
}
value |= (ulong) _buffer[_offset++] << (8*i);
value |= (ulong)_buffer[Offset++] << (8 * i);
mask >>= 1;
}
@@ -118,48 +126,58 @@ namespace SharpCompress.Common.SevenZip
{
ulong value = ReadNumber();
if (value > Int32.MaxValue)
{
throw new NotSupportedException();
}
return (int) value;
return (int)value;
}
public uint ReadUInt32()
{
if (_offset + 4 > _ending)
if (Offset + 4 > _ending)
{
throw new EndOfStreamException();
}
uint res = Get32(_buffer, _offset);
_offset += 4;
uint res = Get32(_buffer, Offset);
Offset += 4;
return res;
}
public ulong ReadUInt64()
{
if (_offset + 8 > _ending)
if (Offset + 8 > _ending)
{
throw new EndOfStreamException();
}
ulong res = Get64(_buffer, _offset);
_offset += 8;
ulong res = Get64(_buffer, Offset);
Offset += 8;
return res;
}
public string ReadString()
{
int ending = _offset;
int ending = Offset;
for (;;)
{
if (ending + 2 > _ending)
{
throw new EndOfStreamException();
}
if (_buffer[ending] == 0 && _buffer[ending + 1] == 0)
{
break;
}
ending += 2;
}
string str = Encoding.Unicode.GetString(_buffer, _offset, ending - _offset);
_offset = ending + 2;
string str = Encoding.Unicode.GetString(_buffer, Offset, ending - Offset);
Offset = ending + 2;
return str;
}

View File

@@ -7,79 +7,37 @@ namespace SharpCompress.Common.SevenZip
{
internal SevenZipEntry(SevenZipFilePart filePart)
{
this.FilePart = filePart;
FilePart = filePart;
}
internal SevenZipFilePart FilePart { get; private set; }
internal SevenZipFilePart FilePart { get; }
public override CompressionType CompressionType
{
get { return FilePart.CompressionType; }
}
public override CompressionType CompressionType { get { return FilePart.CompressionType; } }
public override long Crc
{
get { return FilePart.Header.Crc ?? 0; }
}
public override long Crc { get { return FilePart.Header.Crc ?? 0; } }
public override string Key
{
get { return FilePart.Header.Name; }
}
public override string Key { get { return FilePart.Header.Name; } }
public override long CompressedSize
{
get { return 0; }
}
public override long CompressedSize { get { return 0; } }
public override long Size
{
get { return (long) FilePart.Header.Size; }
}
public override long Size { get { return FilePart.Header.Size; } }
public override DateTime? LastModifiedTime
{
get { return FilePart.Header.MTime; }
}
public override DateTime? LastModifiedTime { get { return FilePart.Header.MTime; } }
public override DateTime? CreatedTime
{
get { return null; }
}
public override DateTime? CreatedTime { get { return null; } }
public override DateTime? LastAccessedTime
{
get { return null; }
}
public override DateTime? LastAccessedTime { get { return null; } }
public override DateTime? ArchivedTime
{
get { return null; }
}
public override DateTime? ArchivedTime { get { return null; } }
public override bool IsEncrypted
{
get { return false; }
}
public override bool IsEncrypted { get { return false; } }
public override bool IsDirectory
{
get { return FilePart.Header.IsDir; }
}
public override bool IsDirectory { get { return FilePart.Header.IsDir; } }
public override bool IsSplit
{
get { return false; }
}
public override bool IsSplit { get { return false; } }
public override int? Attrib
{
get { return (int) FilePart.Header.Attrib; }
}
public override int? Attrib { get { return (int)FilePart.Header.Attrib; } }
internal override IEnumerable<FilePart> Parts
{
get { return FilePart.AsEnumerable<FilePart>(); }
}
internal override IEnumerable<FilePart> Parts { get { return FilePart.AsEnumerable<FilePart>(); } }
}
}

View File

@@ -8,8 +8,8 @@ namespace SharpCompress.Common.SevenZip
internal class SevenZipFilePart : FilePart
{
private CompressionType? type;
private Stream stream;
private ArchiveDatabase database;
private readonly Stream stream;
private readonly ArchiveDatabase database;
internal SevenZipFilePart(Stream stream, ArchiveDatabase database, int index, CFileItem fileEntry)
{
@@ -24,14 +24,11 @@ namespace SharpCompress.Common.SevenZip
}
internal Stream BaseStream { get; private set; }
internal CFileItem Header { get; private set; }
internal CFolder Folder { get; private set; }
internal int Index { get; private set; }
internal CFileItem Header { get; }
internal CFolder Folder { get; }
internal int Index { get; }
internal override string FilePartName
{
get { return Header.Name; }
}
internal override string FilePartName { get { return Header.Name; } }
internal override Stream GetRawStream()
{
@@ -90,17 +87,17 @@ namespace SharpCompress.Common.SevenZip
{
case k_LZMA:
case k_LZMA2:
{
return CompressionType.LZMA;
}
{
return CompressionType.LZMA;
}
case k_PPMD:
{
return CompressionType.PPMd;
}
{
return CompressionType.PPMd;
}
case k_BZip2:
{
return CompressionType.BZip2;
}
{
return CompressionType.BZip2;
}
default:
throw new NotImplementedException();
}

View File

@@ -3,17 +3,17 @@
internal enum EntryType : byte
{
File = 0,
OldFile = (byte) '0',
HardLink = (byte) '1',
SymLink = (byte) '2',
CharDevice = (byte) '3',
BlockDevice = (byte) '4',
Directory = (byte) '5',
Fifo = (byte) '6',
LongLink = (byte) 'K',
LongName = (byte) 'L',
SparseFile = (byte) 'S',
VolumeHeader = (byte) 'V',
GlobalExtendedHeader = (byte) 'g',
OldFile = (byte)'0',
HardLink = (byte)'1',
SymLink = (byte)'2',
CharDevice = (byte)'3',
BlockDevice = (byte)'4',
Directory = (byte)'5',
Fifo = (byte)'6',
LongLink = (byte)'K',
LongName = (byte)'L',
SparseFile = (byte)'S',
VolumeHeader = (byte)'V',
GlobalExtendedHeader = (byte)'g'
}
}

View File

@@ -10,6 +10,7 @@ namespace SharpCompress.Common.Tar.Headers
internal static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
internal string Name { get; set; }
//internal int Mode { get; set; }
//internal int UserId { get; set; }
//internal string UserName { get; set; }
@@ -77,7 +78,9 @@ namespace SharpCompress.Common.Tar.Headers
// pad to multiple of BlockSize bytes, and make sure a terminating null is added
int numPaddingBytes = BlockSize - (nameBytes.Length % BlockSize);
if (numPaddingBytes == 0)
{
numPaddingBytes = BlockSize;
}
output.Write(new byte[numPaddingBytes], 0, numPaddingBytes);
}
@@ -131,11 +134,15 @@ namespace SharpCompress.Common.Tar.Headers
private string ReadLongName(BinaryReader reader, byte[] buffer)
{
var size = ReadSize(buffer);
var nameLength = (int) size;
var nameLength = (int)size;
var nameBytes = reader.ReadBytes(nameLength);
var remainingBytesToRead = BlockSize - (nameLength%BlockSize);
var remainingBytesToRead = BlockSize - (nameLength % BlockSize);
// Read the rest of the block and discard the data
if (remainingBytesToRead < BlockSize) reader.ReadBytes(remainingBytesToRead);
if (remainingBytesToRead < BlockSize)
{
reader.ReadBytes(remainingBytesToRead);
}
return ArchiveEncoding.Default.GetString(nameBytes, 0, nameBytes.Length).TrimNulls();
}

View File

@@ -9,78 +9,38 @@ namespace SharpCompress.Common.Tar
public class TarEntry : Entry
{
private readonly TarFilePart filePart;
private readonly CompressionType type;
internal TarEntry(TarFilePart filePart, CompressionType type)
{
this.filePart = filePart;
this.type = type;
CompressionType = type;
}
public override CompressionType CompressionType
{
get { return type; }
}
public override CompressionType CompressionType { get; }
public override long Crc
{
get { return 0; }
}
public override long Crc { get { return 0; } }
public override string Key
{
get { return filePart.Header.Name; }
}
public override string Key { get { return filePart.Header.Name; } }
public override long CompressedSize
{
get { return filePart.Header.Size; }
}
public override long CompressedSize { get { return filePart.Header.Size; } }
public override long Size
{
get { return filePart.Header.Size; }
}
public override long Size { get { return filePart.Header.Size; } }
public override DateTime? LastModifiedTime
{
get { return filePart.Header.LastModifiedTime; }
}
public override DateTime? LastModifiedTime { get { return filePart.Header.LastModifiedTime; } }
public override DateTime? CreatedTime
{
get { return null; }
}
public override DateTime? CreatedTime { get { return null; } }
public override DateTime? LastAccessedTime
{
get { return null; }
}
public override DateTime? LastAccessedTime { get { return null; } }
public override DateTime? ArchivedTime
{
get { return null; }
}
public override DateTime? ArchivedTime { get { return null; } }
public override bool IsEncrypted
{
get { return false; }
}
public override bool IsEncrypted { get { return false; } }
public override bool IsDirectory
{
get { return filePart.Header.EntryType == EntryType.Directory; }
}
public override bool IsDirectory { get { return filePart.Header.EntryType == EntryType.Directory; } }
public override bool IsSplit
{
get { return false; }
}
public override bool IsSplit { get { return false; } }
internal override IEnumerable<FilePart> Parts
{
get { return filePart.AsEnumerable<FilePart>(); }
}
internal override IEnumerable<FilePart> Parts { get { return filePart.AsEnumerable<FilePart>(); } }
internal static IEnumerable<TarEntry> GetEntries(StreamingMode mode, Stream stream,
CompressionType compressionType)

View File

@@ -14,12 +14,9 @@ namespace SharpCompress.Common.Tar
Header = header;
}
internal TarHeader Header { get; private set; }
internal TarHeader Header { get; }
internal override string FilePartName
{
get { return Header.Name; }
}
internal override string FilePartName { get { return Header.Name; } }
internal override Stream GetCompressedStream()
{

View File

@@ -23,21 +23,22 @@ namespace SharpCompress.Common.Tar
switch (mode)
{
case StreamingMode.Seekable:
{
header.DataStartPosition = reader.BaseStream.Position;
//skip to nearest 512
reader.BaseStream.Position += PadTo512(header.Size);
}
{
header.DataStartPosition = reader.BaseStream.Position;
//skip to nearest 512
reader.BaseStream.Position += PadTo512(header.Size);
}
break;
case StreamingMode.Streaming:
{
header.PackedStream = new TarReadOnlySubStream(stream, header.Size);
}
{
header.PackedStream = new TarReadOnlySubStream(stream, header.Size);
}
break;
default:
{
throw new InvalidFormatException("Invalid StreamingMode");
}
{
throw new InvalidFormatException("Invalid StreamingMode");
}
}
}
catch
@@ -50,7 +51,7 @@ namespace SharpCompress.Common.Tar
private static long PadTo512(long size)
{
int zeros = (int) (size%512);
int zeros = (int)(size % 512);
if (zeros == 0)
{
return size;

View File

@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
namespace SharpCompress.Common.Tar
{
@@ -39,38 +40,22 @@ namespace SharpCompress.Common.Tar
private long BytesLeftToRead { get; set; }
public Stream Stream { get; private set; }
public Stream Stream { get; }
public override bool CanRead
{
get { return true; }
}
public override bool CanRead { get { return true; } }
public override bool CanSeek
{
get { return false; }
}
public override bool CanSeek { get { return false; } }
public override bool CanWrite
{
get { return false; }
}
public override bool CanWrite { get { return false; } }
public override void Flush()
{
throw new System.NotSupportedException();
throw new NotSupportedException();
}
public override long Length
{
get { throw new System.NotSupportedException(); }
}
public override long Length { get { throw new NotSupportedException(); } }
public override long Position
{
get { throw new System.NotSupportedException(); }
set { throw new System.NotSupportedException(); }
}
public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } }
public override int Read(byte[] buffer, int offset, int count)
{
@@ -89,17 +74,17 @@ namespace SharpCompress.Common.Tar
public override long Seek(long offset, SeekOrigin origin)
{
throw new System.NotSupportedException();
throw new NotSupportedException();
}
public override void SetLength(long value)
{
throw new System.NotSupportedException();
throw new NotSupportedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new System.NotSupportedException();
throw new NotSupportedException();
}
}
}

View File

@@ -13,29 +13,20 @@ namespace SharpCompress.Common
Options = options;
}
internal Stream Stream
{
get { return new NonDisposingStream(actualStream); }
}
internal Stream Stream { get { return new NonDisposingStream(actualStream); } }
internal Options Options { get; private set; }
internal Options Options { get; }
/// <summary>
/// RarArchive is the first volume of a multi-part archive.
/// Only Rar 3.0 format and higher
/// </summary>
public virtual bool IsFirstVolume
{
get { return true; }
}
public virtual bool IsFirstVolume { get { return true; } }
/// <summary>
/// RarArchive is part of a multi-part archive.
/// </summary>
public virtual bool IsMultiVolume
{
get { return true; }
}
public virtual bool IsMultiVolume { get { return true; } }
private bool disposed;

View File

@@ -14,8 +14,8 @@ namespace SharpCompress.Common.Zip.Headers
{
Version = reader.ReadUInt16();
VersionNeededToExtract = reader.ReadUInt16();
Flags = (HeaderFlags) reader.ReadUInt16();
CompressionMethod = (ZipCompressionMethod) reader.ReadUInt16();
Flags = (HeaderFlags)reader.ReadUInt16();
CompressionMethod = (ZipCompressionMethod)reader.ReadUInt16();
LastModifiedTime = reader.ReadUInt16();
LastModifiedDate = reader.ReadUInt16();
Crc = reader.ReadUInt32();
@@ -47,8 +47,8 @@ namespace SharpCompress.Common.Zip.Headers
{
writer.Write(Version);
writer.Write(VersionNeededToExtract);
writer.Write((ushort) Flags);
writer.Write((ushort) CompressionMethod);
writer.Write((ushort)Flags);
writer.Write((ushort)CompressionMethod);
writer.Write(LastModifiedTime);
writer.Write(LastModifiedDate);
writer.Write(Crc);
@@ -56,10 +56,11 @@ namespace SharpCompress.Common.Zip.Headers
writer.Write(UncompressedSize);
byte[] nameBytes = EncodeString(Name);
writer.Write((ushort) nameBytes.Length);
writer.Write((ushort)nameBytes.Length);
//writer.Write((ushort)Extra.Length);
writer.Write((ushort) 0);
writer.Write((ushort) Comment.Length);
writer.Write((ushort)0);
writer.Write((ushort)Comment.Length);
writer.Write(DiskNumberStart);
writer.Write(InternalFileAttributes);
@@ -67,6 +68,7 @@ namespace SharpCompress.Common.Zip.Headers
writer.Write(RelativeOffsetOfEntryHeader);
writer.Write(nameBytes);
// writer.Write(Extra);
writer.Write(Comment);
}

View File

@@ -13,8 +13,8 @@ namespace SharpCompress.Common.Zip.Headers
internal override void Read(BinaryReader reader)
{
Version = reader.ReadUInt16();
Flags = (HeaderFlags) reader.ReadUInt16();
CompressionMethod = (ZipCompressionMethod) reader.ReadUInt16();
Flags = (HeaderFlags)reader.ReadUInt16();
CompressionMethod = (ZipCompressionMethod)reader.ReadUInt16();
LastModifiedTime = reader.ReadUInt16();
LastModifiedDate = reader.ReadUInt16();
Crc = reader.ReadUInt32();
@@ -28,17 +28,17 @@ namespace SharpCompress.Common.Zip.Headers
LoadExtra(extra);
var unicodePathExtra = Extra.FirstOrDefault(u => u.Type == ExtraDataType.UnicodePathExtraField);
if (unicodePathExtra!=null)
if (unicodePathExtra != null)
{
Name = ((ExtraUnicodePathExtraField) unicodePathExtra).UnicodeName;
Name = ((ExtraUnicodePathExtraField)unicodePathExtra).UnicodeName;
}
}
internal override void Write(BinaryWriter writer)
{
writer.Write(Version);
writer.Write((ushort) Flags);
writer.Write((ushort) CompressionMethod);
writer.Write((ushort)Flags);
writer.Write((ushort)CompressionMethod);
writer.Write(LastModifiedTime);
writer.Write(LastModifiedDate);
writer.Write(Crc);
@@ -47,8 +47,9 @@ namespace SharpCompress.Common.Zip.Headers
byte[] nameBytes = EncodeString(Name);
writer.Write((ushort) nameBytes.Length);
writer.Write((ushort) 0);
writer.Write((ushort)nameBytes.Length);
writer.Write((ushort)0);
//if (Extra != null)
//{
// writer.Write(Extra);

View File

@@ -8,6 +8,7 @@ namespace SharpCompress.Common.Zip.Headers
WinZipAes = 0x9901,
NotImplementedExtraData = 0xFFFF,
// Third Party Mappings
// -Info-ZIP Unicode Path Extra Field
UnicodePathExtraField = 0x7075
@@ -22,17 +23,14 @@ namespace SharpCompress.Common.Zip.Headers
internal class ExtraUnicodePathExtraField : ExtraData
{
internal byte Version
{
get { return this.DataBytes[0]; }
}
internal byte Version { get { return DataBytes[0]; } }
internal byte[] NameCRC32
{
get
{
var crc = new byte[4];
Buffer.BlockCopy(this.DataBytes, 1, crc, 0, 4);
Buffer.BlockCopy(DataBytes, 1, crc, 0, 4);
return crc;
}
}
@@ -42,8 +40,8 @@ namespace SharpCompress.Common.Zip.Headers
get
{
// PathNamelength = dataLength - Version(1 byte) - NameCRC32(4 bytes)
var length = this.Length - 5;
var nameStr = Encoding.UTF8.GetString(this.DataBytes, 5, length);
var length = Length - 5;
var nameStr = Encoding.UTF8.GetString(DataBytes, 5, length);
return nameStr;
}
}
@@ -51,25 +49,25 @@ namespace SharpCompress.Common.Zip.Headers
internal static class LocalEntryHeaderExtraFactory
{
internal static ExtraData Create(ExtraDataType type,ushort length, byte[] extraData)
internal static ExtraData Create(ExtraDataType type, ushort length, byte[] extraData)
{
switch (type)
{
case ExtraDataType.UnicodePathExtraField:
return new ExtraUnicodePathExtraField()
{
Type = type,
Length = length,
DataBytes = extraData
};
return new ExtraUnicodePathExtraField
{
Type = type,
Length = length,
DataBytes = extraData
};
default:
return new ExtraData
{
Type = type,
Length = length,
DataBytes = extraData
};
{
Type = type,
Length = length,
DataBytes = extraData
};
}
}
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.IO;
namespace SharpCompress.Common.Zip.Headers
{
@@ -9,12 +10,12 @@ namespace SharpCompress.Common.Zip.Headers
{
}
internal override void Read(System.IO.BinaryReader reader)
internal override void Read(BinaryReader reader)
{
throw new NotImplementedException();
}
internal override void Write(System.IO.BinaryWriter writer)
internal override void Write(BinaryWriter writer)
{
throw new NotImplementedException();
}

View File

@@ -19,13 +19,14 @@ namespace SharpCompress.Common.Zip.Headers
get
{
if (Name.EndsWith("/"))
{
return true;
}
//.NET Framework 4.5 : System.IO.Compression::CreateFromDirectory() probably writes backslashes to headers
return CompressedSize == 0
&& UncompressedSize == 0
&& Name.EndsWith("\\");
&& UncompressedSize == 0
&& Name.EndsWith("\\");
}
}
@@ -77,10 +78,10 @@ namespace SharpCompress.Common.Zip.Headers
protected void LoadExtra(byte[] extra)
{
for (int i = 0; i < extra.Length-4;)
for (int i = 0; i < extra.Length - 4;)
{
ExtraDataType type = (ExtraDataType)DataConverter.LittleEndian.GetUInt16(extra, i);
if (!Enum.IsDefined(typeof (ExtraDataType), type))
if (!Enum.IsDefined(typeof(ExtraDataType), type))
{
type = ExtraDataType.NotImplementedExtraData;
}
@@ -88,7 +89,7 @@ namespace SharpCompress.Common.Zip.Headers
ushort length = DataConverter.LittleEndian.GetUInt16(extra, i + 2);
byte[] data = new byte[length];
Buffer.BlockCopy(extra, i + 4, data, 0, length);
Extra.Add(LocalEntryHeaderExtraFactory.Create(type,length,data));
Extra.Add(LocalEntryHeaderExtraFactory.Create(type, length, data));
i += length + 4;
}

View File

@@ -6,6 +6,6 @@
LocalEntry,
DirectoryEntry,
DirectoryEnd,
Split,
Split
}
}

View File

@@ -9,7 +9,6 @@ namespace SharpCompress.Common.Zip
Decrypt
}
internal class PkwareTraditionalCryptoStream : Stream
{
private readonly PkwareTraditionalEncryptionData encryptor;
@@ -24,40 +23,27 @@ namespace SharpCompress.Common.Zip
this.mode = mode;
}
public override bool CanRead { get { return (mode == CryptoMode.Decrypt); } }
public override bool CanRead
{
get { return (mode == CryptoMode.Decrypt); }
}
public override bool CanSeek { get { return false; } }
public override bool CanSeek
{
get { return false; }
}
public override bool CanWrite { get { return (mode == CryptoMode.Encrypt); } }
public override bool CanWrite
{
get { return (mode == CryptoMode.Encrypt); }
}
public override long Length { get { throw new NotSupportedException(); } }
public override long Length
{
get { throw new NotSupportedException(); }
}
public override long Position
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}
public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } }
public override int Read(byte[] buffer, int offset, int count)
{
if (mode == CryptoMode.Encrypt)
{
throw new NotSupportedException("This stream does not encrypt via Read()");
}
if (buffer == null)
{
throw new ArgumentNullException("buffer");
}
byte[] temp = new byte[count];
int readBytes = stream.Read(temp, 0, count);
@@ -69,7 +55,9 @@ namespace SharpCompress.Common.Zip
public override void Write(byte[] buffer, int offset, int count)
{
if (mode == CryptoMode.Decrypt)
{
throw new NotSupportedException("This stream does not Decrypt via Write()");
}
if (count == 0)
{

View File

@@ -19,8 +19,8 @@ namespace SharpCompress.Common.Zip
{
get
{
ushort t = (ushort) ((ushort) (_Keys[2] & 0xFFFF) | 2);
return (byte) ((t*(t ^ 1)) >> 8);
ushort t = (ushort)((ushort)(_Keys[2] & 0xFFFF) | 2);
return (byte)((t * (t ^ 1)) >> 8);
}
}
@@ -29,13 +29,13 @@ namespace SharpCompress.Common.Zip
{
var encryptor = new PkwareTraditionalEncryptionData(password);
byte[] plainTextHeader = encryptor.Decrypt(encryptionHeader, encryptionHeader.Length);
if (plainTextHeader[11] != (byte) ((header.Crc >> 24) & 0xff))
if (plainTextHeader[11] != (byte)((header.Crc >> 24) & 0xff))
{
if (!FlagUtility.HasFlag(header.Flags, HeaderFlags.UsePostDataDescriptor))
{
throw new CryptographicException("The password did not match.");
}
if (plainTextHeader[11] != (byte) ((header.LastModifiedTime >> 8) & 0xff))
if (plainTextHeader[11] != (byte)((header.LastModifiedTime >> 8) & 0xff))
{
throw new CryptographicException("The password did not match.");
}
@@ -43,17 +43,18 @@ namespace SharpCompress.Common.Zip
return encryptor;
}
public byte[] Decrypt(byte[] cipherText, int length)
{
if (length > cipherText.Length)
{
throw new ArgumentOutOfRangeException("length",
"Bad length during Decryption: the length parameter must be smaller than or equal to the size of the destination array.");
}
var plainText = new byte[length];
for (int i = 0; i < length; i++)
{
var C = (byte) (cipherText[i] ^ MagicByte);
var C = (byte)(cipherText[i] ^ MagicByte);
UpdateKeys(C);
plainText[i] = C;
}
@@ -63,17 +64,21 @@ namespace SharpCompress.Common.Zip
public byte[] Encrypt(byte[] plainText, int length)
{
if (plainText == null)
{
throw new ArgumentNullException("plaintext");
}
if (length > plainText.Length)
{
throw new ArgumentOutOfRangeException("length",
"Bad length during Encryption: The length parameter must be smaller than or equal to the size of the destination array.");
}
var cipherText = new byte[length];
for (int i = 0; i < length; i++)
{
byte C = plainText[i];
cipherText[i] = (byte) (plainText[i] ^ MagicByte);
cipherText[i] = (byte)(plainText[i] ^ MagicByte);
UpdateKeys(C);
}
return cipherText;
@@ -83,7 +88,9 @@ namespace SharpCompress.Common.Zip
{
byte[] p = StringToByteArray(password);
for (int i = 0; i < password.Length; i++)
{
UpdateKeys(p[i]);
}
}
internal static byte[] StringToByteArray(string value, Encoding encoding)
@@ -99,10 +106,10 @@ namespace SharpCompress.Common.Zip
private void UpdateKeys(byte byteValue)
{
_Keys[0] = (UInt32) crc32.ComputeCrc32((int) _Keys[0], byteValue);
_Keys[1] = _Keys[1] + (byte) _Keys[0];
_Keys[1] = _Keys[1]*0x08088405 + 1;
_Keys[2] = (UInt32) crc32.ComputeCrc32((int) _Keys[2], (byte) (_Keys[1] >> 24));
_Keys[0] = (UInt32)crc32.ComputeCrc32((int)_Keys[0], byteValue);
_Keys[1] = _Keys[1] + (byte)_Keys[0];
_Keys[1] = _Keys[1] * 0x08088405 + 1;
_Keys[2] = (UInt32)crc32.ComputeCrc32((int)_Keys[2], (byte)(_Keys[1] >> 24));
}
}
}

View File

@@ -24,10 +24,7 @@ namespace SharpCompress.Common.Zip
return base.GetCompressedStream();
}
internal string Comment
{
get { return (Header as DirectoryEntryHeader).Comment; }
}
internal string Comment { get { return (Header as DirectoryEntryHeader).Comment; } }
private void LoadLocalHeader()
{

View File

@@ -35,9 +35,10 @@ namespace SharpCompress.Common.Zip
if (iterationCount > MAX_ITERATIONS_FOR_DIRECTORY_HEADER)
{
throw new ArchiveException(
"Could not find Zip file Directory at the end of the file. File may be corrupted.");
"Could not find Zip file Directory at the end of the file. File may be corrupted.");
}
} while (signature != DIRECTORY_END_HEADER_BYTES);
}
while (signature != DIRECTORY_END_HEADER_BYTES);
var entry = new DirectoryEndHeader();
entry.Read(reader);
@@ -55,6 +56,7 @@ namespace SharpCompress.Common.Zip
{
yield break;
}
//entry could be zero bytes so we need to know that.
directoryEntryHeader.HasData = directoryEntryHeader.CompressedSize != 0;
yield return directoryEntryHeader;

View File

@@ -1,3 +1,4 @@
#if !NO_CRYPTO
using System;
using System.IO;

View File

@@ -1,3 +1,4 @@
#if !NO_CRYPTO
using System;
using System.Security.Cryptography;

View File

@@ -4,6 +4,6 @@
{
KeySize128 = 1,
KeySize192 = 2,
KeySize256 = 3,
KeySize256 = 3
}
}

View File

@@ -7,14 +7,13 @@ namespace SharpCompress.Common.Zip
public class ZipEntry : Entry
{
private readonly ZipFilePart filePart;
private readonly DateTime? lastModifiedTime;
internal ZipEntry(ZipFilePart filePart)
{
if (filePart != null)
{
this.filePart = filePart;
lastModifiedTime = Utility.DosDateToDateTime(filePart.Header.LastModifiedDate,
LastModifiedTime = Utility.DosDateToDateTime(filePart.Header.LastModifiedDate,
filePart.Header.LastModifiedTime);
}
}
@@ -26,91 +25,55 @@ namespace SharpCompress.Common.Zip
switch (filePart.Header.CompressionMethod)
{
case ZipCompressionMethod.BZip2:
{
return CompressionType.BZip2;
}
{
return CompressionType.BZip2;
}
case ZipCompressionMethod.Deflate:
{
return CompressionType.Deflate;
}
{
return CompressionType.Deflate;
}
case ZipCompressionMethod.LZMA:
{
return CompressionType.LZMA;
}
{
return CompressionType.LZMA;
}
case ZipCompressionMethod.PPMd:
{
return CompressionType.PPMd;
}
{
return CompressionType.PPMd;
}
case ZipCompressionMethod.None:
{
return CompressionType.None;
}
{
return CompressionType.None;
}
default:
{
return CompressionType.Unknown;
}
{
return CompressionType.Unknown;
}
}
}
}
public override long Crc
{
get { return filePart.Header.Crc; }
}
public override long Crc { get { return filePart.Header.Crc; } }
public override string Key
{
get { return filePart.Header.Name; }
}
public override string Key { get { return filePart.Header.Name; } }
public override long CompressedSize
{
get { return filePart.Header.CompressedSize; }
}
public override long CompressedSize { get { return filePart.Header.CompressedSize; } }
public override long Size
{
get { return filePart.Header.UncompressedSize; }
}
public override long Size { get { return filePart.Header.UncompressedSize; } }
public override DateTime? LastModifiedTime
{
get { return lastModifiedTime; }
}
public override DateTime? LastModifiedTime { get; }
public override DateTime? CreatedTime
{
get { return null; }
}
public override DateTime? CreatedTime { get { return null; } }
public override DateTime? LastAccessedTime
{
get { return null; }
}
public override DateTime? LastAccessedTime { get { return null; } }
public override DateTime? ArchivedTime
{
get { return null; }
}
public override DateTime? ArchivedTime { get { return null; } }
public override bool IsEncrypted
{
get { return FlagUtility.HasFlag(filePart.Header.Flags, HeaderFlags.Encrypted); }
}
public override bool IsEncrypted { get { return FlagUtility.HasFlag(filePart.Header.Flags, HeaderFlags.Encrypted); } }
public override bool IsDirectory
{
get { return filePart.Header.IsDirectory; }
}
public override bool IsDirectory { get { return filePart.Header.IsDirectory; } }
public override bool IsSplit
{
get { return false; }
}
public override bool IsSplit { get { return false; } }
internal override IEnumerable<FilePart> Parts
{
get { return filePart.AsEnumerable<FilePart>(); }
}
internal override IEnumerable<FilePart> Parts { get { return filePart.AsEnumerable<FilePart>(); } }
}
}

View File

@@ -18,17 +18,13 @@ namespace SharpCompress.Common.Zip
{
Header = header;
header.Part = this;
this.BaseStream = stream;
BaseStream = stream;
}
internal Stream BaseStream { get; private set; }
internal ZipFileEntry Header { get; set; }
internal override string FilePartName
{
get { return Header.Name; }
}
internal override string FilePartName { get { return Header.Name; } }
internal override Stream GetCompressedStream()
{
@@ -55,79 +51,76 @@ namespace SharpCompress.Common.Zip
protected abstract Stream CreateBaseStream();
protected bool LeaveStreamOpen
{
get { return FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor); }
}
protected bool LeaveStreamOpen { get { return FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor); } }
protected Stream CreateDecompressionStream(Stream stream)
{
switch (Header.CompressionMethod)
{
case ZipCompressionMethod.None:
{
return stream;
}
{
return stream;
}
case ZipCompressionMethod.Deflate:
{
return new DeflateStream(stream, CompressionMode.Decompress);
}
{
return new DeflateStream(stream, CompressionMode.Decompress);
}
case ZipCompressionMethod.BZip2:
{
return new BZip2Stream(stream, CompressionMode.Decompress);
}
{
return new BZip2Stream(stream, CompressionMode.Decompress);
}
case ZipCompressionMethod.LZMA:
{
if (FlagUtility.HasFlag(Header.Flags, HeaderFlags.Encrypted))
{
if (FlagUtility.HasFlag(Header.Flags, HeaderFlags.Encrypted))
{
throw new NotSupportedException("LZMA with pkware encryption.");
}
var reader = new BinaryReader(stream);
reader.ReadUInt16(); //LZMA version
var props = new byte[reader.ReadUInt16()];
reader.Read(props, 0, props.Length);
return new LzmaStream(props, stream,
Header.CompressedSize > 0 ? Header.CompressedSize - 4 - props.Length : -1,
FlagUtility.HasFlag(Header.Flags, HeaderFlags.Bit1)
? -1
: (long)Header.UncompressedSize);
throw new NotSupportedException("LZMA with pkware encryption.");
}
var reader = new BinaryReader(stream);
reader.ReadUInt16(); //LZMA version
var props = new byte[reader.ReadUInt16()];
reader.Read(props, 0, props.Length);
return new LzmaStream(props, stream,
Header.CompressedSize > 0 ? Header.CompressedSize - 4 - props.Length : -1,
FlagUtility.HasFlag(Header.Flags, HeaderFlags.Bit1)
? -1
: (long)Header.UncompressedSize);
}
case ZipCompressionMethod.PPMd:
{
var props = new byte[2];
stream.Read(props, 0, props.Length);
return new PpmdStream(new PpmdProperties(props), stream, false);
}
{
var props = new byte[2];
stream.Read(props, 0, props.Length);
return new PpmdStream(new PpmdProperties(props), stream, false);
}
case ZipCompressionMethod.WinzipAes:
{
ExtraData data = Header.Extra.Where(x => x.Type == ExtraDataType.WinZipAes).SingleOrDefault();
if (data == null)
{
ExtraData data = Header.Extra.Where(x => x.Type == ExtraDataType.WinZipAes).SingleOrDefault();
if (data == null)
{
throw new InvalidFormatException("No Winzip AES extra data found.");
}
if (data.Length != 7)
{
throw new InvalidFormatException("Winzip data length is not 7.");
}
ushort method = DataConverter.LittleEndian.GetUInt16(data.DataBytes, 0);
if (method != 0x01 && method != 0x02)
{
throw new InvalidFormatException("Unexpected vendor version number for WinZip AES metadata");
}
ushort vendorId = DataConverter.LittleEndian.GetUInt16(data.DataBytes, 2);
if (vendorId != 0x4541)
{
throw new InvalidFormatException("Unexpected vendor ID for WinZip AES metadata");
}
Header.CompressionMethod = (ZipCompressionMethod)DataConverter.LittleEndian.GetUInt16(data.DataBytes, 5);
return CreateDecompressionStream(stream);
throw new InvalidFormatException("No Winzip AES extra data found.");
}
if (data.Length != 7)
{
throw new InvalidFormatException("Winzip data length is not 7.");
}
ushort method = DataConverter.LittleEndian.GetUInt16(data.DataBytes, 0);
if (method != 0x01 && method != 0x02)
{
throw new InvalidFormatException("Unexpected vendor version number for WinZip AES metadata");
}
ushort vendorId = DataConverter.LittleEndian.GetUInt16(data.DataBytes, 2);
if (vendorId != 0x4541)
{
throw new InvalidFormatException("Unexpected vendor ID for WinZip AES metadata");
}
Header.CompressionMethod = (ZipCompressionMethod)DataConverter.LittleEndian.GetUInt16(data.DataBytes, 5);
return CreateDecompressionStream(stream);
}
default:
{
throw new NotSupportedException("CompressionMethod: " + Header.CompressionMethod);
}
{
throw new NotSupportedException("CompressionMethod: " + Header.CompressionMethod);
}
}
}
@@ -137,7 +130,7 @@ namespace SharpCompress.Common.Zip
#if !NO_CRYPTO
&& ((Header.PkwareTraditionalEncryptionData != null)
|| (Header.WinzipAesEncryptionData != null)))
#else
#else
&& (Header.PkwareTraditionalEncryptionData != null))
#endif
{

View File

@@ -2,7 +2,6 @@
using System.IO;
using SharpCompress.Common.Zip.Headers;
using SharpCompress.IO;
using System.Linq;
namespace SharpCompress.Common.Zip
{
@@ -18,10 +17,9 @@ namespace SharpCompress.Common.Zip
private const uint ZIP64_END_OF_CENTRAL_DIRECTORY = 0x06064b50;
private const uint ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR = 0x07064b50;
protected LocalEntryHeader lastEntryHeader;
private string password;
private StreamingMode mode;
private readonly string password;
private readonly StreamingMode mode;
protected ZipHeaderFactory(StreamingMode mode, string password)
{
@@ -34,55 +32,55 @@ namespace SharpCompress.Common.Zip
switch (headerBytes)
{
case ENTRY_HEADER_BYTES:
{
var entryHeader = new LocalEntryHeader();
entryHeader.Read(reader);
LoadHeader(entryHeader, reader.BaseStream);
{
var entryHeader = new LocalEntryHeader();
entryHeader.Read(reader);
LoadHeader(entryHeader, reader.BaseStream);
lastEntryHeader = entryHeader;
return entryHeader;
}
lastEntryHeader = entryHeader;
return entryHeader;
}
case DIRECTORY_START_HEADER_BYTES:
{
var entry = new DirectoryEntryHeader();
entry.Read(reader);
return entry;
}
{
var entry = new DirectoryEntryHeader();
entry.Read(reader);
return entry;
}
case POST_DATA_DESCRIPTOR:
{
if (FlagUtility.HasFlag(lastEntryHeader.Flags, HeaderFlags.UsePostDataDescriptor))
{
if (FlagUtility.HasFlag(lastEntryHeader.Flags, HeaderFlags.UsePostDataDescriptor))
{
lastEntryHeader.Crc = reader.ReadUInt32();
lastEntryHeader.CompressedSize = reader.ReadUInt32();
lastEntryHeader.UncompressedSize = reader.ReadUInt32();
}
else
{
reader.ReadUInt32();
reader.ReadUInt32();
reader.ReadUInt32();
}
return null;
lastEntryHeader.Crc = reader.ReadUInt32();
lastEntryHeader.CompressedSize = reader.ReadUInt32();
lastEntryHeader.UncompressedSize = reader.ReadUInt32();
}
else
{
reader.ReadUInt32();
reader.ReadUInt32();
reader.ReadUInt32();
}
return null;
}
case DIGITAL_SIGNATURE:
return null;
case DIRECTORY_END_HEADER_BYTES:
{
var entry = new DirectoryEndHeader();
entry.Read(reader);
return entry;
}
{
var entry = new DirectoryEndHeader();
entry.Read(reader);
return entry;
}
case SPLIT_ARCHIVE_HEADER_BYTES:
{
return new SplitHeader();
}
{
return new SplitHeader();
}
case ZIP64_END_OF_CENTRAL_DIRECTORY:
case ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR:
{
var entry = new IgnoreHeader(ZipHeaderType.Ignore);
entry.Read(reader);
return entry;
}
{
var entry = new IgnoreHeader(ZipHeaderType.Ignore);
entry.Read(reader);
return entry;
}
default:
throw new NotSupportedException("Unknown header: " + headerBytes);
}
@@ -115,7 +113,7 @@ namespace SharpCompress.Common.Zip
FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.UsePostDataDescriptor))
{
throw new NotSupportedException(
"SharpCompress cannot currently read non-seekable Zip Streams with encrypted data that has been written in a non-seekable manner.");
"SharpCompress cannot currently read non-seekable Zip Streams with encrypted data that has been written in a non-seekable manner.");
}
if (password == null)
{
@@ -154,6 +152,7 @@ namespace SharpCompress.Common.Zip
{
return;
}
//if (FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.UsePostDataDescriptor))
//{
// entryHeader.PackedStream = new ReadOnlySubStream(stream);
@@ -163,21 +162,22 @@ namespace SharpCompress.Common.Zip
switch (mode)
{
case StreamingMode.Seekable:
{
entryHeader.DataStartPosition = stream.Position;
stream.Position += entryHeader.CompressedSize;
}
{
entryHeader.DataStartPosition = stream.Position;
stream.Position += entryHeader.CompressedSize;
}
break;
case StreamingMode.Streaming:
{
entryHeader.PackedStream = stream;
}
{
entryHeader.PackedStream = stream;
}
break;
default:
{
throw new InvalidFormatException("Invalid StreamingMode");
}
{
throw new InvalidFormatException("Invalid StreamingMode");
}
}
//}
}
}

View File

@@ -24,6 +24,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System;
using System.IO;
namespace SharpCompress.Compressor.ADC
@@ -40,9 +41,13 @@ namespace SharpCompress.Compressor.ADC
static int GetChunkType(byte byt)
{
if ((byt & 0x80) == 0x80)
{
return Plain;
}
if ((byt & 0x40) == 0x40)
{
return ThreeByte;
}
return TwoByte;
}
@@ -100,7 +105,9 @@ namespace SharpCompress.Compressor.ADC
output = null;
if (input == null || input.Length == 0)
{
return 0;
}
int start = (int)input.Position;
int position = (int)input.Position;
@@ -116,7 +123,9 @@ namespace SharpCompress.Compressor.ADC
{
int readByte = input.ReadByte();
if (readByte == -1)
{
break;
}
chunkType = GetChunkType((byte)readByte);
@@ -199,7 +208,9 @@ namespace SharpCompress.Compressor.ADC
}
if (full)
{
break;
}
}
output = new byte[outPosition];
@@ -207,4 +218,4 @@ namespace SharpCompress.Compressor.ADC
return position - start;
}
}
}
}

View File

@@ -24,6 +24,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System;
using System.IO;
namespace SharpCompress.Compressor.ADC
@@ -37,18 +38,22 @@ namespace SharpCompress.Compressor.ADC
/// This stream holds the compressed data
/// </summary>
private readonly Stream stream;
/// <summary>
/// Is this instance disposed?
/// </summary>
private bool isDisposed;
/// <summary>
/// Position in decompressed data
/// </summary>
private long position = 0;
private long position;
/// <summary>
/// Buffer with currently used chunk of decompressed data
/// </summary>
private byte[] outBuffer;
/// <summary>
/// Position in buffer of decompressed data
/// </summary>
@@ -62,36 +67,22 @@ namespace SharpCompress.Compressor.ADC
public ADCStream(Stream stream, CompressionMode compressionMode = CompressionMode.Decompress)
{
if (compressionMode == CompressionMode.Compress)
{
throw new NotSupportedException();
}
this.stream = stream;
}
public override bool CanRead
{
get { return stream.CanRead; }
}
public override bool CanRead { get { return stream.CanRead; } }
public override bool CanSeek
{
get { return false; }
}
public override bool CanSeek { get { return false; } }
public override bool CanWrite
{
get { return false; }
}
public override bool CanWrite { get { return false; } }
public override long Length
{
get { throw new NotSupportedException(); }
}
public override long Length { get { throw new NotSupportedException(); } }
public override long Position
{
get { return position; }
set { throw new NotSupportedException(); }
}
public override long Position { get { return position; } set { throw new NotSupportedException(); } }
public override void Flush()
{
@@ -100,7 +91,9 @@ namespace SharpCompress.Compressor.ADC
protected override void Dispose(bool disposing)
{
if (isDisposed)
{
return;
}
isDisposed = true;
base.Dispose(disposing);
}
@@ -108,15 +101,25 @@ namespace SharpCompress.Compressor.ADC
public override int Read(byte[] buffer, int offset, int count)
{
if (count == 0)
{
return 0;
}
if (buffer == null)
{
throw new ArgumentNullException("buffer");
}
if (count < 0)
{
throw new ArgumentOutOfRangeException("count");
}
if (offset < buffer.GetLowerBound(0))
{
throw new ArgumentOutOfRangeException("offset");
}
if ((offset + count) > buffer.GetLength(0))
{
throw new ArgumentOutOfRangeException("count");
}
int size = -1;
@@ -141,7 +144,9 @@ namespace SharpCompress.Compressor.ADC
size = ADCBase.Decompress(stream, out outBuffer);
outPosition = 0;
if (size == 0 || outBuffer == null || outBuffer.Length == 0)
{
return copied;
}
}
Array.Copy(outBuffer, outPosition, buffer, inPosition, toCopy);
@@ -166,4 +171,4 @@ namespace SharpCompress.Compressor.ADC
throw new NotSupportedException();
}
}
}
}

View File

@@ -39,63 +39,63 @@ namespace SharpCompress.Compressor.BZip2
public const int N_GROUPS = 6;
public const int G_SIZE = 50;
public const int N_ITERS = 4;
public const int MAX_SELECTORS = (2 + (900000/G_SIZE));
public const int MAX_SELECTORS = (2 + (900000 / G_SIZE));
public const int NUM_OVERSHOOT_BYTES = 20;
public static 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,
419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
936, 638
};
{
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,
419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
936, 638
};
}
}

View File

@@ -27,10 +27,10 @@ namespace SharpCompress.Compressor.BZip2
this.stream = new CBZip2InputStream(stream, decompressContacted, leaveOpen);
}
}
public void Finish()
{
(this.stream as CBZip2OutputStream)?.Finish();
(stream as CBZip2OutputStream)?.Finish();
}
protected override void Dispose(bool disposing)
@@ -46,38 +46,22 @@ namespace SharpCompress.Compressor.BZip2
}
}
public CompressionMode Mode { get; private set; }
public CompressionMode Mode { get; }
public override bool CanRead
{
get { return stream.CanRead; }
}
public override bool CanRead { get { return stream.CanRead; } }
public override bool CanSeek
{
get { return stream.CanSeek; }
}
public override bool CanSeek { get { return stream.CanSeek; } }
public override bool CanWrite
{
get { return stream.CanWrite; }
}
public override bool CanWrite { get { return stream.CanWrite; } }
public override void Flush()
{
stream.Flush();
}
public override long Length
{
get { return stream.Length; }
}
public override long Length { get { return stream.Length; } }
public override long Position
{
get { return stream.Position; }
set { stream.Position = value; }
}
public override long Position { get { return stream.Position; } set { stream.Position = value; } }
public override int Read(byte[] buffer, int offset, int count)
{

View File

@@ -93,16 +93,16 @@ namespace SharpCompress.Compressor.BZip2
private int bsBuff;
private int bsLive;
private CRC mCrc = new CRC();
private readonly CRC mCrc = new CRC();
private bool[] inUse = new bool[256];
private readonly bool[] inUse = new bool[256];
private int nInUse;
private char[] seqToUnseq = new char[256];
private char[] unseqToSeq = new char[256];
private readonly char[] seqToUnseq = new char[256];
private readonly char[] unseqToSeq = new char[256];
private char[] selector = new char[BZip2Constants.MAX_SELECTORS];
private char[] selectorMtf = new char[BZip2Constants.MAX_SELECTORS];
private readonly char[] selector = new char[BZip2Constants.MAX_SELECTORS];
private readonly char[] selectorMtf = new char[BZip2Constants.MAX_SELECTORS];
private int[] tt;
private char[] ll8;
@@ -111,17 +111,17 @@ namespace SharpCompress.Compressor.BZip2
freq table collected to save a pass over the data
during decompression.
*/
private int[] unzftab = new int[256];
private readonly int[] unzftab = new int[256];
private int[][] limit = InitIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE);
private int[][] basev = InitIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE);
private int[][] perm = InitIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE);
private int[] minLens = new int[BZip2Constants.N_GROUPS];
private readonly int[][] limit = InitIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE);
private readonly int[][] basev = InitIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE);
private readonly int[][] perm = InitIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE);
private readonly int[] minLens = new int[BZip2Constants.N_GROUPS];
private Stream bsStream;
private bool leaveOpen;
private bool streamEnd = false;
private bool streamEnd;
private int currentChar = -1;
@@ -137,12 +137,12 @@ namespace SharpCompress.Compressor.BZip2
private int storedBlockCRC, storedCombinedCRC;
private int computedBlockCRC, computedCombinedCRC;
private bool decompressConcatenated;
private readonly bool decompressConcatenated;
private int i2, count, chPrev, ch2;
private int i, tPos;
private int rNToGo = 0;
private int rTPos = 0;
private int rNToGo;
private int rTPos;
private int j2;
private char z;
private bool isDisposed;
@@ -198,34 +198,31 @@ namespace SharpCompress.Compressor.BZip2
{
return -1;
}
else
int retChar = currentChar;
switch (currentState)
{
int retChar = currentChar;
switch (currentState)
{
case START_BLOCK_STATE:
break;
case RAND_PART_A_STATE:
break;
case RAND_PART_B_STATE:
SetupRandPartB();
break;
case RAND_PART_C_STATE:
SetupRandPartC();
break;
case NO_RAND_PART_A_STATE:
break;
case NO_RAND_PART_B_STATE:
SetupNoRandPartB();
break;
case NO_RAND_PART_C_STATE:
SetupNoRandPartC();
break;
default:
break;
}
return retChar;
case START_BLOCK_STATE:
break;
case RAND_PART_A_STATE:
break;
case RAND_PART_B_STATE:
SetupRandPartB();
break;
case RAND_PART_C_STATE:
SetupRandPartC();
break;
case NO_RAND_PART_A_STATE:
break;
case NO_RAND_PART_B_STATE:
SetupNoRandPartB();
break;
case NO_RAND_PART_C_STATE:
SetupNoRandPartC();
break;
default:
break;
}
return retChar;
}
private bool Initialize(bool isFirstStream)
@@ -250,7 +247,7 @@ namespace SharpCompress.Compressor.BZip2
}
SetDecompressStructureSizes(magic3 - '0');
this.bsLive = 0;
bsLive = 0;
computedCombinedCRC = 0;
return true;
}
@@ -275,7 +272,9 @@ namespace SharpCompress.Compressor.BZip2
}
if (Complete())
{
return;
}
}
if (magic1 != 0x31 || magic2 != 0x41 || magic3 != 0x59
@@ -357,11 +356,13 @@ namespace SharpCompress.Compressor.BZip2
{
try
{
if (this.bsStream != null)
if (bsStream != null)
{
if (!leaveOpen)
this.bsStream.Dispose();
this.bsStream = null;
{
bsStream.Dispose();
}
bsStream = null;
}
}
catch
@@ -424,12 +425,12 @@ namespace SharpCompress.Compressor.BZip2
private int BsGetIntVS(int numBits)
{
return (int)BsR(numBits);
return BsR(numBits);
}
private int BsGetInt32()
{
return (int)BsGetint();
return BsGetint();
}
private void HbCreateDecodeTables(int[] limit, int[] basev,
@@ -748,7 +749,8 @@ namespace SharpCompress.Compressor.BZip2
}
nextSym = perm[zt][zvec - basev[zt][zn]];
}
} while (nextSym == BZip2Constants.RUNA || nextSym == BZip2Constants.RUNB);
}
while (nextSym == BZip2Constants.RUNA || nextSym == BZip2Constants.RUNB);
s++;
ch = seqToUnseq[yy[0]];
@@ -765,7 +767,6 @@ namespace SharpCompress.Compressor.BZip2
{
BlockOverrun();
}
continue;
}
else
{
@@ -841,7 +842,6 @@ namespace SharpCompress.Compressor.BZip2
}
nextSym = perm[zt][zvec - basev[zt][zn]];
}
continue;
}
}
}
@@ -863,7 +863,7 @@ namespace SharpCompress.Compressor.BZip2
for (i = 0; i <= last; i++)
{
ch = (char)ll8[i];
ch = ll8[i];
tt[cftab[ch]] = i;
cftab[ch]++;
}
@@ -904,7 +904,7 @@ namespace SharpCompress.Compressor.BZip2
}
}
rNToGo--;
ch2 ^= (int)((rNToGo == 1) ? 1 : 0);
ch2 ^= (rNToGo == 1) ? 1 : 0;
i2++;
currentChar = ch2;
@@ -980,7 +980,7 @@ namespace SharpCompress.Compressor.BZip2
private void SetupRandPartC()
{
if (j2 < (int)z)
if (j2 < z)
{
currentChar = ch2;
mCrc.UpdateCRC(ch2);
@@ -1024,7 +1024,7 @@ namespace SharpCompress.Compressor.BZip2
private void SetupNoRandPartC()
{
if (j2 < (int)z)
if (j2 < z)
{
currentChar = ch2;
mCrc.UpdateCRC(ch2);
@@ -1071,7 +1071,9 @@ namespace SharpCompress.Compressor.BZip2
{
c = ReadByte();
if (c == -1)
{
break;
}
buffer[k + offset] = (byte)c;
}
return k;
@@ -1090,30 +1092,14 @@ namespace SharpCompress.Compressor.BZip2
{
}
public override bool CanRead
{
get { return true; }
}
public override bool CanRead { get { return true; } }
public override bool CanSeek
{
get { return false; }
}
public override bool CanSeek { get { return false; } }
public override bool CanWrite
{
get { return false; }
}
public override bool CanWrite { get { return false; } }
public override long Length
{
get { return 0; }
}
public override long Length { get { return 0; } }
public override long Position
{
get { return 0; }
set { }
}
public override long Position { get { return 0; } set { } }
}
}

View File

@@ -69,8 +69,8 @@ namespace SharpCompress.Compressor.BZip2
{
if (inUse[i])
{
seqToUnseq[nInUse] = (char) i;
unseqToSeq[i] = (char) nInUse;
seqToUnseq[nInUse] = (char)i;
unseqToSeq[i] = (char)nInUse;
nInUse++;
}
}
@@ -87,8 +87,8 @@ namespace SharpCompress.Compressor.BZip2
bool tooLong;
int[] heap = new int[BZip2Constants.MAX_ALPHA_SIZE + 2];
int[] weight = new int[BZip2Constants.MAX_ALPHA_SIZE*2];
int[] parent = new int[BZip2Constants.MAX_ALPHA_SIZE*2];
int[] weight = new int[BZip2Constants.MAX_ALPHA_SIZE * 2];
int[] parent = new int[BZip2Constants.MAX_ALPHA_SIZE * 2];
for (i = 0; i < alphaSize; i++)
{
@@ -187,12 +187,12 @@ namespace SharpCompress.Compressor.BZip2
nNodes++;
parent[n1] = parent[n2] = nNodes;
weight[nNodes] = (int) ((uint) ((weight[n1] & 0xffffff00)
+ (weight[n2] & 0xffffff00))
| (uint) (1 + (((weight[n1] & 0x000000ff) >
(weight[n2] & 0x000000ff))
? (weight[n1] & 0x000000ff)
: (weight[n2] & 0x000000ff))));
weight[nNodes] = (int)((uint)((weight[n1] & 0xffffff00)
+ (weight[n2] & 0xffffff00))
| (uint)(1 + (((weight[n1] & 0x000000ff) >
(weight[n2] & 0x000000ff))
? (weight[n1] & 0x000000ff)
: (weight[n2] & 0x000000ff))));
parent[nNodes] = -1;
nHeap++;
@@ -209,7 +209,7 @@ namespace SharpCompress.Compressor.BZip2
heap[zz] = tmp;
}
}
if (!(nNodes < (BZip2Constants.MAX_ALPHA_SIZE*2)))
if (!(nNodes < (BZip2Constants.MAX_ALPHA_SIZE * 2)))
{
Panic();
}
@@ -224,7 +224,7 @@ namespace SharpCompress.Compressor.BZip2
k = parent[k];
j++;
}
len[i - 1] = (char) j;
len[i - 1] = (char)j;
if (j > maxLen)
{
tooLong = true;
@@ -239,7 +239,7 @@ namespace SharpCompress.Compressor.BZip2
for (i = 1; i < alphaSize; i++)
{
j = weight[i] >> 8;
j = 1 + (j/2);
j = 1 + (j / 2);
weight[i] = j << 8;
}
}
@@ -260,23 +260,23 @@ namespace SharpCompress.Compressor.BZip2
always: in the range 0 .. 9.
The current block size is 100000 * this number.
*/
private int blockSize100k;
private readonly int blockSize100k;
private bool blockRandomised;
private int bytesOut;
private int bsBuff;
private int bsLive;
private CRC mCrc = new CRC();
private readonly CRC mCrc = new CRC();
private bool[] inUse = new bool[256];
private readonly bool[] inUse = new bool[256];
private int nInUse;
private char[] seqToUnseq = new char[256];
private char[] unseqToSeq = new char[256];
private readonly char[] seqToUnseq = new char[256];
private readonly char[] unseqToSeq = new char[256];
private char[] selector = new char[BZip2Constants.MAX_SELECTORS];
private char[] selectorMtf = new char[BZip2Constants.MAX_SELECTORS];
private readonly char[] selector = new char[BZip2Constants.MAX_SELECTORS];
private readonly char[] selectorMtf = new char[BZip2Constants.MAX_SELECTORS];
private char[] block;
private int[] quadrant;
@@ -286,21 +286,21 @@ namespace SharpCompress.Compressor.BZip2
private int nMTF;
private int[] mtfFreq = new int[BZip2Constants.MAX_ALPHA_SIZE];
private readonly int[] mtfFreq = new int[BZip2Constants.MAX_ALPHA_SIZE];
/*
* Used when sorting. If too many long comparisons
* happen, we stop sorting, randomise the block
* slightly, and try again.
*/
private int workFactor;
private readonly int workFactor;
private int workDone;
private int workLimit;
private bool firstAttempt;
private int nBlocksRandomised;
private int currentChar = -1;
private int runLength = 0;
private int runLength;
public CBZip2OutputStream(Stream inStream)
: this(inStream, 9, false)
@@ -319,8 +319,8 @@ namespace SharpCompress.Compressor.BZip2
zptr = null;
ftab = null;
inStream.WriteByte((byte) 'B');
inStream.WriteByte((byte) 'Z');
inStream.WriteByte((byte)'B');
inStream.WriteByte((byte)'Z');
BsSetStream(inStream, leaveOpen);
@@ -347,7 +347,7 @@ namespace SharpCompress.Compressor.BZip2
public override void WriteByte(byte bv)
{
int b = (256 + bv)%256;
int b = (256 + bv) % 256;
if (currentChar != -1)
{
if (currentChar == b)
@@ -381,40 +381,40 @@ namespace SharpCompress.Compressor.BZip2
inUse[currentChar] = true;
for (int i = 0; i < runLength; i++)
{
mCrc.UpdateCRC((char) currentChar);
mCrc.UpdateCRC((char)currentChar);
}
switch (runLength)
{
case 1:
last++;
block[last + 1] = (char) currentChar;
block[last + 1] = (char)currentChar;
break;
case 2:
last++;
block[last + 1] = (char) currentChar;
block[last + 1] = (char)currentChar;
last++;
block[last + 1] = (char) currentChar;
block[last + 1] = (char)currentChar;
break;
case 3:
last++;
block[last + 1] = (char) currentChar;
block[last + 1] = (char)currentChar;
last++;
block[last + 1] = (char) currentChar;
block[last + 1] = (char)currentChar;
last++;
block[last + 1] = (char) currentChar;
block[last + 1] = (char)currentChar;
break;
default:
inUse[runLength - 4] = true;
last++;
block[last + 1] = (char) currentChar;
block[last + 1] = (char)currentChar;
last++;
block[last + 1] = (char) currentChar;
block[last + 1] = (char)currentChar;
last++;
block[last + 1] = (char) currentChar;
block[last + 1] = (char)currentChar;
last++;
block[last + 1] = (char) currentChar;
block[last + 1] = (char)currentChar;
last++;
block[last + 1] = (char) (runLength - 4);
block[last + 1] = (char)(runLength - 4);
break;
}
}
@@ -426,7 +426,7 @@ namespace SharpCompress.Compressor.BZip2
}
}
private bool disposed = false;
private bool disposed;
protected override void Dispose(bool disposing)
{
@@ -442,7 +442,9 @@ namespace SharpCompress.Compressor.BZip2
disposed = true;
base.Dispose();
if (!leaveOpen)
{
bsStream.Dispose();
}
bsStream = null;
}
}
@@ -493,6 +495,7 @@ namespace SharpCompress.Compressor.BZip2
// blockNo++;
mCrc.InitialiseCRC();
last = -1;
// ch = 0;
for (int i = 0; i < 256; i++)
@@ -501,13 +504,13 @@ namespace SharpCompress.Compressor.BZip2
}
/* 20 is just a paranoia constant */
allowableBlockSize = BZip2Constants.baseBlockSize*blockSize100k - 20;
allowableBlockSize = BZip2Constants.baseBlockSize * blockSize100k - 20;
}
private void EndBlock()
{
blockCRC = mCrc.GetFinalCRC();
combinedCRC = (combinedCRC << 1) | (int) (((uint) combinedCRC) >> 31);
combinedCRC = (combinedCRC << 1) | (int)(((uint)combinedCRC) >> 31);
combinedCRC ^= blockCRC;
/* sort the block and establish posn of original string */
@@ -609,7 +612,7 @@ namespace SharpCompress.Compressor.BZip2
int ch = (bsBuff >> 24);
try
{
bsStream.WriteByte((byte) ch); // write 8-bit
bsStream.WriteByte((byte)ch); // write 8-bit
}
catch (IOException e)
{
@@ -628,7 +631,7 @@ namespace SharpCompress.Compressor.BZip2
int ch = (bsBuff >> 24);
try
{
bsStream.WriteByte((byte) ch); // write 8-bit
bsStream.WriteByte((byte)ch); // write 8-bit
}
catch (IOException e)
{
@@ -673,7 +676,7 @@ namespace SharpCompress.Compressor.BZip2
{
for (v = 0; v < alphaSize; v++)
{
len[t][v] = (char) GREATER_ICOST;
len[t][v] = (char)GREATER_ICOST;
}
}
@@ -713,7 +716,7 @@ namespace SharpCompress.Compressor.BZip2
gs = 0;
while (nPart > 0)
{
tFreq = remF/nPart;
tFreq = remF / nPart;
ge = gs - 1;
aFreq = 0;
while (aFreq < tFreq && ge < alphaSize - 1)
@@ -723,7 +726,7 @@ namespace SharpCompress.Compressor.BZip2
}
if (ge > gs && nPart != nGroups && nPart != 1
&& ((nGroups - nPart)%2 == 1))
&& ((nGroups - nPart) % 2 == 1))
{
aFreq -= mtfFreq[ge];
ge--;
@@ -733,11 +736,11 @@ namespace SharpCompress.Compressor.BZip2
{
if (v >= gs && v <= ge)
{
len[nPart - 1][v] = (char) LESSER_ICOST;
len[nPart - 1][v] = (char)LESSER_ICOST;
}
else
{
len[nPart - 1][v] = (char) GREATER_ICOST;
len[nPart - 1][v] = (char)GREATER_ICOST;
}
}
@@ -800,12 +803,12 @@ namespace SharpCompress.Compressor.BZip2
for (i = gs; i <= ge; i++)
{
short icv = szptr[i];
cost0 += (short) len[0][icv];
cost1 += (short) len[1][icv];
cost2 += (short) len[2][icv];
cost3 += (short) len[3][icv];
cost4 += (short) len[4][icv];
cost5 += (short) len[5][icv];
cost0 += (short)len[0][icv];
cost1 += (short)len[1][icv];
cost2 += (short)len[2][icv];
cost3 += (short)len[3][icv];
cost4 += (short)len[4][icv];
cost5 += (short)len[5][icv];
}
cost[0] = cost0;
cost[1] = cost1;
@@ -821,7 +824,7 @@ namespace SharpCompress.Compressor.BZip2
short icv = szptr[i];
for (t = 0; t < nGroups; t++)
{
cost[t] += (short) len[t][icv];
cost[t] += (short)len[t][icv];
}
}
}
@@ -843,7 +846,7 @@ namespace SharpCompress.Compressor.BZip2
;
totc += bc;
fave[bt]++;
selector[nSelectors] = (char) bt;
selector[nSelectors] = (char)bt;
nSelectors++;
/*
@@ -874,19 +877,18 @@ namespace SharpCompress.Compressor.BZip2
{
Panic();
}
if (!(nSelectors < 32768 && nSelectors <= (2 + (900000/BZip2Constants.G_SIZE))))
if (!(nSelectors < 32768 && nSelectors <= (2 + (900000 / BZip2Constants.G_SIZE))))
{
Panic();
}
/* Compute MTF values for the selectors. */
{
char[] pos = new char[BZip2Constants.N_GROUPS];
char ll_i, tmp2, tmp;
for (i = 0; i < nGroups; i++)
{
pos[i] = (char) i;
pos[i] = (char)i;
}
for (i = 0; i < nSelectors; i++)
{
@@ -901,7 +903,7 @@ namespace SharpCompress.Compressor.BZip2
pos[j] = tmp2;
}
pos[0] = tmp;
selectorMtf[i] = (char) j;
selectorMtf[i] = (char)j;
}
}
@@ -942,7 +944,7 @@ namespace SharpCompress.Compressor.BZip2
inUse16[i] = false;
for (j = 0; j < 16; j++)
{
if (inUse[i*16 + j])
if (inUse[i * 16 + j])
{
inUse16[i] = true;
}
@@ -968,7 +970,7 @@ namespace SharpCompress.Compressor.BZip2
{
for (j = 0; j < 16; j++)
{
if (inUse[i*16 + j])
if (inUse[i * 16 + j])
{
BsW(1, 1);
}
@@ -1244,7 +1246,7 @@ namespace SharpCompress.Compressor.BZip2
{
break;
}
n = ((int) block[zptr[unLo] + d + 1]) - med;
n = block[zptr[unLo] + d + 1] - med;
if (n == 0)
{
int temp = 0;
@@ -1268,7 +1270,7 @@ namespace SharpCompress.Compressor.BZip2
{
break;
}
n = ((int) block[zptr[unHi] + d + 1]) - med;
n = block[zptr[unHi] + d + 1] - med;
if (n == 0)
{
int temp = 0;
@@ -1349,14 +1351,14 @@ namespace SharpCompress.Compressor.BZip2
// if (verbosity >= 4) fprintf ( stderr, " sort initialise ...\n" );
for (i = 0; i < BZip2Constants.NUM_OVERSHOOT_BYTES; i++)
{
block[last + i + 2] = block[(i%(last + 1)) + 1];
block[last + i + 2] = block[(i % (last + 1)) + 1];
}
for (i = 0; i <= last + BZip2Constants.NUM_OVERSHOOT_BYTES; i++)
{
quadrant[i] = 0;
}
block[0] = (char) (block[last + 1]);
block[0] = block[last + 1];
if (last < 4000)
{
@@ -1428,11 +1430,12 @@ namespace SharpCompress.Compressor.BZip2
int h = 1;
do
{
h = 3*h + 1;
} while (h <= 256);
h = 3 * h + 1;
}
while (h <= 256);
do
{
h = h/3;
h = h / 3;
for (i = h; i <= 255; i++)
{
vv = runningOrder[i];
@@ -1450,7 +1453,8 @@ namespace SharpCompress.Compressor.BZip2
}
runningOrder[j] = vv;
}
} while (h != 1);
}
while (h != 1);
}
/*
@@ -1571,7 +1575,7 @@ namespace SharpCompress.Compressor.BZip2
{
if (rNToGo == 0)
{
rNToGo = (char) BZip2Constants.rNums[rTPos];
rNToGo = (char)BZip2Constants.rNums[rTPos];
rTPos++;
if (rTPos == 512)
{
@@ -1579,9 +1583,10 @@ namespace SharpCompress.Compressor.BZip2
}
}
rNToGo--;
block[i + 1] ^= (char) ((rNToGo == 1) ? 1 : 0);
block[i + 1] ^= (char)((rNToGo == 1) ? 1 : 0);
// handle 16 bit signed numbers
block[i + 1] &= (char) 0xFF;
block[i + 1] &= (char)0xFF;
inUse[block[i + 1]] = true;
}
@@ -1591,7 +1596,7 @@ namespace SharpCompress.Compressor.BZip2
{
int i;
workLimit = workFactor*last;
workLimit = workFactor * last;
workDone = 0;
blockRandomised = false;
firstAttempt = true;
@@ -1763,7 +1768,8 @@ namespace SharpCompress.Compressor.BZip2
k -= 4;
workDone++;
} while (k >= 0);
}
while (k >= 0);
return false;
}
@@ -1775,16 +1781,16 @@ namespace SharpCompress.Compressor.BZip2
usually small, typically <= 20.
*/
private int[] incs =
{
1, 4, 13, 40, 121, 364, 1093, 3280,
9841, 29524, 88573, 265720,
797161, 2391484
};
private readonly int[] incs =
{
1, 4, 13, 40, 121, 364, 1093, 3280,
9841, 29524, 88573, 265720,
797161, 2391484
};
private void AllocateCompressStructures()
{
int n = BZip2Constants.baseBlockSize*blockSize100k;
int n = BZip2Constants.baseBlockSize * blockSize100k;
block = new char[(n + 1 + BZip2Constants.NUM_OVERSHOOT_BYTES)];
quadrant = new int[(n + BZip2Constants.NUM_OVERSHOOT_BYTES)];
zptr = new int[n];
@@ -1809,8 +1815,7 @@ namespace SharpCompress.Compressor.BZip2
*/
// szptr = zptr;
szptr = new short[2*n];
szptr = new short[2 * n];
}
private void GenerateMTFValues()
@@ -1835,10 +1840,9 @@ namespace SharpCompress.Compressor.BZip2
zPend = 0;
for (i = 0; i < nInUse; i++)
{
yy[i] = (char) i;
yy[i] = (char)i;
}
for (i = 0; i <= last; i++)
{
char ll_i;
@@ -1868,15 +1872,15 @@ namespace SharpCompress.Compressor.BZip2
zPend--;
while (true)
{
switch (zPend%2)
switch (zPend % 2)
{
case 0:
szptr[wr] = (short) BZip2Constants.RUNA;
szptr[wr] = BZip2Constants.RUNA;
wr++;
mtfFreq[BZip2Constants.RUNA]++;
break;
case 1:
szptr[wr] = (short) BZip2Constants.RUNB;
szptr[wr] = BZip2Constants.RUNB;
wr++;
mtfFreq[BZip2Constants.RUNB]++;
break;
@@ -1886,12 +1890,12 @@ namespace SharpCompress.Compressor.BZip2
{
break;
}
zPend = (zPend - 2)/2;
zPend = (zPend - 2) / 2;
}
;
zPend = 0;
}
szptr[wr] = (short) (j + 1);
szptr[wr] = (short)(j + 1);
wr++;
mtfFreq[j + 1]++;
}
@@ -1902,15 +1906,15 @@ namespace SharpCompress.Compressor.BZip2
zPend--;
while (true)
{
switch (zPend%2)
switch (zPend % 2)
{
case 0:
szptr[wr] = (short) BZip2Constants.RUNA;
szptr[wr] = BZip2Constants.RUNA;
wr++;
mtfFreq[BZip2Constants.RUNA]++;
break;
case 1:
szptr[wr] = (short) BZip2Constants.RUNB;
szptr[wr] = BZip2Constants.RUNB;
wr++;
mtfFreq[BZip2Constants.RUNB]++;
break;
@@ -1919,11 +1923,11 @@ namespace SharpCompress.Compressor.BZip2
{
break;
}
zPend = (zPend - 2)/2;
zPend = (zPend - 2) / 2;
}
}
szptr[wr] = (short) EOB;
szptr[wr] = (short)EOB;
wr++;
mtfFreq[EOB]++;
@@ -1952,30 +1956,14 @@ namespace SharpCompress.Compressor.BZip2
}
}
public override bool CanRead
{
get { return false; }
}
public override bool CanRead { get { return false; } }
public override bool CanSeek
{
get { return false; }
}
public override bool CanSeek { get { return false; } }
public override bool CanWrite
{
get { return true; }
}
public override bool CanWrite { get { return true; } }
public override long Length
{
get { return 0; }
}
public override long Length { get { return 0; } }
public override long Position
{
get { return 0; }
set { }
}
public override long Position { get { return 0; } set { } }
}
}

View File

@@ -32,136 +32,136 @@ namespace SharpCompress.Compressor.BZip2
internal class CRC
{
public static int[] crc32Table =
{
unchecked((int) 0x00000000), unchecked((int) 0x04c11db7), unchecked((int) 0x09823b6e),
unchecked((int) 0x0d4326d9),
unchecked((int) 0x130476dc), unchecked((int) 0x17c56b6b), unchecked((int) 0x1a864db2),
unchecked((int) 0x1e475005),
unchecked((int) 0x2608edb8), unchecked((int) 0x22c9f00f), unchecked((int) 0x2f8ad6d6),
unchecked((int) 0x2b4bcb61),
unchecked((int) 0x350c9b64), unchecked((int) 0x31cd86d3), unchecked((int) 0x3c8ea00a),
unchecked((int) 0x384fbdbd),
unchecked((int) 0x4c11db70), unchecked((int) 0x48d0c6c7), unchecked((int) 0x4593e01e),
unchecked((int) 0x4152fda9),
unchecked((int) 0x5f15adac), unchecked((int) 0x5bd4b01b), unchecked((int) 0x569796c2),
unchecked((int) 0x52568b75),
unchecked((int) 0x6a1936c8), unchecked((int) 0x6ed82b7f), unchecked((int) 0x639b0da6),
unchecked((int) 0x675a1011),
unchecked((int) 0x791d4014), unchecked((int) 0x7ddc5da3), unchecked((int) 0x709f7b7a),
unchecked((int) 0x745e66cd),
unchecked((int) 0x9823b6e0), unchecked((int) 0x9ce2ab57), unchecked((int) 0x91a18d8e),
unchecked((int) 0x95609039),
unchecked((int) 0x8b27c03c), unchecked((int) 0x8fe6dd8b), unchecked((int) 0x82a5fb52),
unchecked((int) 0x8664e6e5),
unchecked((int) 0xbe2b5b58), unchecked((int) 0xbaea46ef), unchecked((int) 0xb7a96036),
unchecked((int) 0xb3687d81),
unchecked((int) 0xad2f2d84), unchecked((int) 0xa9ee3033), unchecked((int) 0xa4ad16ea),
unchecked((int) 0xa06c0b5d),
unchecked((int) 0xd4326d90), unchecked((int) 0xd0f37027), unchecked((int) 0xddb056fe),
unchecked((int) 0xd9714b49),
unchecked((int) 0xc7361b4c), unchecked((int) 0xc3f706fb), unchecked((int) 0xceb42022),
unchecked((int) 0xca753d95),
unchecked((int) 0xf23a8028), unchecked((int) 0xf6fb9d9f), unchecked((int) 0xfbb8bb46),
unchecked((int) 0xff79a6f1),
unchecked((int) 0xe13ef6f4), unchecked((int) 0xe5ffeb43), unchecked((int) 0xe8bccd9a),
unchecked((int) 0xec7dd02d),
unchecked((int) 0x34867077), unchecked((int) 0x30476dc0), unchecked((int) 0x3d044b19),
unchecked((int) 0x39c556ae),
unchecked((int) 0x278206ab), unchecked((int) 0x23431b1c), unchecked((int) 0x2e003dc5),
unchecked((int) 0x2ac12072),
unchecked((int) 0x128e9dcf), unchecked((int) 0x164f8078), unchecked((int) 0x1b0ca6a1),
unchecked((int) 0x1fcdbb16),
unchecked((int) 0x018aeb13), unchecked((int) 0x054bf6a4), unchecked((int) 0x0808d07d),
unchecked((int) 0x0cc9cdca),
unchecked((int) 0x7897ab07), unchecked((int) 0x7c56b6b0), unchecked((int) 0x71159069),
unchecked((int) 0x75d48dde),
unchecked((int) 0x6b93dddb), unchecked((int) 0x6f52c06c), unchecked((int) 0x6211e6b5),
unchecked((int) 0x66d0fb02),
unchecked((int) 0x5e9f46bf), unchecked((int) 0x5a5e5b08), unchecked((int) 0x571d7dd1),
unchecked((int) 0x53dc6066),
unchecked((int) 0x4d9b3063), unchecked((int) 0x495a2dd4), unchecked((int) 0x44190b0d),
unchecked((int) 0x40d816ba),
unchecked((int) 0xaca5c697), unchecked((int) 0xa864db20), unchecked((int) 0xa527fdf9),
unchecked((int) 0xa1e6e04e),
unchecked((int) 0xbfa1b04b), unchecked((int) 0xbb60adfc), unchecked((int) 0xb6238b25),
unchecked((int) 0xb2e29692),
unchecked((int) 0x8aad2b2f), unchecked((int) 0x8e6c3698), unchecked((int) 0x832f1041),
unchecked((int) 0x87ee0df6),
unchecked((int) 0x99a95df3), unchecked((int) 0x9d684044), unchecked((int) 0x902b669d),
unchecked((int) 0x94ea7b2a),
unchecked((int) 0xe0b41de7), unchecked((int) 0xe4750050), unchecked((int) 0xe9362689),
unchecked((int) 0xedf73b3e),
unchecked((int) 0xf3b06b3b), unchecked((int) 0xf771768c), unchecked((int) 0xfa325055),
unchecked((int) 0xfef34de2),
unchecked((int) 0xc6bcf05f), unchecked((int) 0xc27dede8), unchecked((int) 0xcf3ecb31),
unchecked((int) 0xcbffd686),
unchecked((int) 0xd5b88683), unchecked((int) 0xd1799b34), unchecked((int) 0xdc3abded),
unchecked((int) 0xd8fba05a),
unchecked((int) 0x690ce0ee), unchecked((int) 0x6dcdfd59), unchecked((int) 0x608edb80),
unchecked((int) 0x644fc637),
unchecked((int) 0x7a089632), unchecked((int) 0x7ec98b85), unchecked((int) 0x738aad5c),
unchecked((int) 0x774bb0eb),
unchecked((int) 0x4f040d56), unchecked((int) 0x4bc510e1), unchecked((int) 0x46863638),
unchecked((int) 0x42472b8f),
unchecked((int) 0x5c007b8a), unchecked((int) 0x58c1663d), unchecked((int) 0x558240e4),
unchecked((int) 0x51435d53),
unchecked((int) 0x251d3b9e), unchecked((int) 0x21dc2629), unchecked((int) 0x2c9f00f0),
unchecked((int) 0x285e1d47),
unchecked((int) 0x36194d42), unchecked((int) 0x32d850f5), unchecked((int) 0x3f9b762c),
unchecked((int) 0x3b5a6b9b),
unchecked((int) 0x0315d626), unchecked((int) 0x07d4cb91), unchecked((int) 0x0a97ed48),
unchecked((int) 0x0e56f0ff),
unchecked((int) 0x1011a0fa), unchecked((int) 0x14d0bd4d), unchecked((int) 0x19939b94),
unchecked((int) 0x1d528623),
unchecked((int) 0xf12f560e), unchecked((int) 0xf5ee4bb9), unchecked((int) 0xf8ad6d60),
unchecked((int) 0xfc6c70d7),
unchecked((int) 0xe22b20d2), unchecked((int) 0xe6ea3d65), unchecked((int) 0xeba91bbc),
unchecked((int) 0xef68060b),
unchecked((int) 0xd727bbb6), unchecked((int) 0xd3e6a601), unchecked((int) 0xdea580d8),
unchecked((int) 0xda649d6f),
unchecked((int) 0xc423cd6a), unchecked((int) 0xc0e2d0dd), unchecked((int) 0xcda1f604),
unchecked((int) 0xc960ebb3),
unchecked((int) 0xbd3e8d7e), unchecked((int) 0xb9ff90c9), unchecked((int) 0xb4bcb610),
unchecked((int) 0xb07daba7),
unchecked((int) 0xae3afba2), unchecked((int) 0xaafbe615), unchecked((int) 0xa7b8c0cc),
unchecked((int) 0xa379dd7b),
unchecked((int) 0x9b3660c6), unchecked((int) 0x9ff77d71), unchecked((int) 0x92b45ba8),
unchecked((int) 0x9675461f),
unchecked((int) 0x8832161a), unchecked((int) 0x8cf30bad), unchecked((int) 0x81b02d74),
unchecked((int) 0x857130c3),
unchecked((int) 0x5d8a9099), unchecked((int) 0x594b8d2e), unchecked((int) 0x5408abf7),
unchecked((int) 0x50c9b640),
unchecked((int) 0x4e8ee645), unchecked((int) 0x4a4ffbf2), unchecked((int) 0x470cdd2b),
unchecked((int) 0x43cdc09c),
unchecked((int) 0x7b827d21), unchecked((int) 0x7f436096), unchecked((int) 0x7200464f),
unchecked((int) 0x76c15bf8),
unchecked((int) 0x68860bfd), unchecked((int) 0x6c47164a), unchecked((int) 0x61043093),
unchecked((int) 0x65c52d24),
unchecked((int) 0x119b4be9), unchecked((int) 0x155a565e), unchecked((int) 0x18197087),
unchecked((int) 0x1cd86d30),
unchecked((int) 0x029f3d35), unchecked((int) 0x065e2082), unchecked((int) 0x0b1d065b),
unchecked((int) 0x0fdc1bec),
unchecked((int) 0x3793a651), unchecked((int) 0x3352bbe6), unchecked((int) 0x3e119d3f),
unchecked((int) 0x3ad08088),
unchecked((int) 0x2497d08d), unchecked((int) 0x2056cd3a), unchecked((int) 0x2d15ebe3),
unchecked((int) 0x29d4f654),
unchecked((int) 0xc5a92679), unchecked((int) 0xc1683bce), unchecked((int) 0xcc2b1d17),
unchecked((int) 0xc8ea00a0),
unchecked((int) 0xd6ad50a5), unchecked((int) 0xd26c4d12), unchecked((int) 0xdf2f6bcb),
unchecked((int) 0xdbee767c),
unchecked((int) 0xe3a1cbc1), unchecked((int) 0xe760d676), unchecked((int) 0xea23f0af),
unchecked((int) 0xeee2ed18),
unchecked((int) 0xf0a5bd1d), unchecked((int) 0xf464a0aa), unchecked((int) 0xf9278673),
unchecked((int) 0xfde69bc4),
unchecked((int) 0x89b8fd09), unchecked((int) 0x8d79e0be), unchecked((int) 0x803ac667),
unchecked((int) 0x84fbdbd0),
unchecked((int) 0x9abc8bd5), unchecked((int) 0x9e7d9662), unchecked((int) 0x933eb0bb),
unchecked((int) 0x97ffad0c),
unchecked((int) 0xafb010b1), unchecked((int) 0xab710d06), unchecked((int) 0xa6322bdf),
unchecked((int) 0xa2f33668),
unchecked((int) 0xbcb4666d), unchecked((int) 0xb8757bda), unchecked((int) 0xb5365d03),
unchecked((int) 0xb1f740b4)
};
{
0x00000000, 0x04c11db7, 0x09823b6e,
0x0d4326d9,
0x130476dc, 0x17c56b6b, 0x1a864db2,
0x1e475005,
0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
0x2b4bcb61,
0x350c9b64, 0x31cd86d3, 0x3c8ea00a,
0x384fbdbd,
0x4c11db70, 0x48d0c6c7, 0x4593e01e,
0x4152fda9,
0x5f15adac, 0x5bd4b01b, 0x569796c2,
0x52568b75,
0x6a1936c8, 0x6ed82b7f, 0x639b0da6,
0x675a1011,
0x791d4014, 0x7ddc5da3, 0x709f7b7a,
0x745e66cd,
unchecked((int)0x9823b6e0), unchecked((int)0x9ce2ab57), unchecked((int)0x91a18d8e),
unchecked((int)0x95609039),
unchecked((int)0x8b27c03c), unchecked((int)0x8fe6dd8b), unchecked((int)0x82a5fb52),
unchecked((int)0x8664e6e5),
unchecked((int)0xbe2b5b58), unchecked((int)0xbaea46ef), unchecked((int)0xb7a96036),
unchecked((int)0xb3687d81),
unchecked((int)0xad2f2d84), unchecked((int)0xa9ee3033), unchecked((int)0xa4ad16ea),
unchecked((int)0xa06c0b5d),
unchecked((int)0xd4326d90), unchecked((int)0xd0f37027), unchecked((int)0xddb056fe),
unchecked((int)0xd9714b49),
unchecked((int)0xc7361b4c), unchecked((int)0xc3f706fb), unchecked((int)0xceb42022),
unchecked((int)0xca753d95),
unchecked((int)0xf23a8028), unchecked((int)0xf6fb9d9f), unchecked((int)0xfbb8bb46),
unchecked((int)0xff79a6f1),
unchecked((int)0xe13ef6f4), unchecked((int)0xe5ffeb43), unchecked((int)0xe8bccd9a),
unchecked((int)0xec7dd02d),
0x34867077, 0x30476dc0, 0x3d044b19,
0x39c556ae,
0x278206ab, 0x23431b1c, 0x2e003dc5,
0x2ac12072,
0x128e9dcf, 0x164f8078, 0x1b0ca6a1,
0x1fcdbb16,
0x018aeb13, 0x054bf6a4, 0x0808d07d,
0x0cc9cdca,
0x7897ab07, 0x7c56b6b0, 0x71159069,
0x75d48dde,
0x6b93dddb, 0x6f52c06c, 0x6211e6b5,
0x66d0fb02,
0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1,
0x53dc6066,
0x4d9b3063, 0x495a2dd4, 0x44190b0d,
0x40d816ba,
unchecked((int)0xaca5c697), unchecked((int)0xa864db20), unchecked((int)0xa527fdf9),
unchecked((int)0xa1e6e04e),
unchecked((int)0xbfa1b04b), unchecked((int)0xbb60adfc), unchecked((int)0xb6238b25),
unchecked((int)0xb2e29692),
unchecked((int)0x8aad2b2f), unchecked((int)0x8e6c3698), unchecked((int)0x832f1041),
unchecked((int)0x87ee0df6),
unchecked((int)0x99a95df3), unchecked((int)0x9d684044), unchecked((int)0x902b669d),
unchecked((int)0x94ea7b2a),
unchecked((int)0xe0b41de7), unchecked((int)0xe4750050), unchecked((int)0xe9362689),
unchecked((int)0xedf73b3e),
unchecked((int)0xf3b06b3b), unchecked((int)0xf771768c), unchecked((int)0xfa325055),
unchecked((int)0xfef34de2),
unchecked((int)0xc6bcf05f), unchecked((int)0xc27dede8), unchecked((int)0xcf3ecb31),
unchecked((int)0xcbffd686),
unchecked((int)0xd5b88683), unchecked((int)0xd1799b34), unchecked((int)0xdc3abded),
unchecked((int)0xd8fba05a),
0x690ce0ee, 0x6dcdfd59, 0x608edb80,
0x644fc637,
0x7a089632, 0x7ec98b85, 0x738aad5c,
0x774bb0eb,
0x4f040d56, 0x4bc510e1, 0x46863638,
0x42472b8f,
0x5c007b8a, 0x58c1663d, 0x558240e4,
0x51435d53,
0x251d3b9e, 0x21dc2629, 0x2c9f00f0,
0x285e1d47,
0x36194d42, 0x32d850f5, 0x3f9b762c,
0x3b5a6b9b,
0x0315d626, 0x07d4cb91, 0x0a97ed48,
0x0e56f0ff,
0x1011a0fa, 0x14d0bd4d, 0x19939b94,
0x1d528623,
unchecked((int)0xf12f560e), unchecked((int)0xf5ee4bb9), unchecked((int)0xf8ad6d60),
unchecked((int)0xfc6c70d7),
unchecked((int)0xe22b20d2), unchecked((int)0xe6ea3d65), unchecked((int)0xeba91bbc),
unchecked((int)0xef68060b),
unchecked((int)0xd727bbb6), unchecked((int)0xd3e6a601), unchecked((int)0xdea580d8),
unchecked((int)0xda649d6f),
unchecked((int)0xc423cd6a), unchecked((int)0xc0e2d0dd), unchecked((int)0xcda1f604),
unchecked((int)0xc960ebb3),
unchecked((int)0xbd3e8d7e), unchecked((int)0xb9ff90c9), unchecked((int)0xb4bcb610),
unchecked((int)0xb07daba7),
unchecked((int)0xae3afba2), unchecked((int)0xaafbe615), unchecked((int)0xa7b8c0cc),
unchecked((int)0xa379dd7b),
unchecked((int)0x9b3660c6), unchecked((int)0x9ff77d71), unchecked((int)0x92b45ba8),
unchecked((int)0x9675461f),
unchecked((int)0x8832161a), unchecked((int)0x8cf30bad), unchecked((int)0x81b02d74),
unchecked((int)0x857130c3),
0x5d8a9099, 0x594b8d2e, 0x5408abf7,
0x50c9b640,
0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b,
0x43cdc09c,
0x7b827d21, 0x7f436096, 0x7200464f,
0x76c15bf8,
0x68860bfd, 0x6c47164a, 0x61043093,
0x65c52d24,
0x119b4be9, 0x155a565e, 0x18197087,
0x1cd86d30,
0x029f3d35, 0x065e2082, 0x0b1d065b,
0x0fdc1bec,
0x3793a651, 0x3352bbe6, 0x3e119d3f,
0x3ad08088,
0x2497d08d, 0x2056cd3a, 0x2d15ebe3,
0x29d4f654,
unchecked((int)0xc5a92679), unchecked((int)0xc1683bce), unchecked((int)0xcc2b1d17),
unchecked((int)0xc8ea00a0),
unchecked((int)0xd6ad50a5), unchecked((int)0xd26c4d12), unchecked((int)0xdf2f6bcb),
unchecked((int)0xdbee767c),
unchecked((int)0xe3a1cbc1), unchecked((int)0xe760d676), unchecked((int)0xea23f0af),
unchecked((int)0xeee2ed18),
unchecked((int)0xf0a5bd1d), unchecked((int)0xf464a0aa), unchecked((int)0xf9278673),
unchecked((int)0xfde69bc4),
unchecked((int)0x89b8fd09), unchecked((int)0x8d79e0be), unchecked((int)0x803ac667),
unchecked((int)0x84fbdbd0),
unchecked((int)0x9abc8bd5), unchecked((int)0x9e7d9662), unchecked((int)0x933eb0bb),
unchecked((int)0x97ffad0c),
unchecked((int)0xafb010b1), unchecked((int)0xab710d06), unchecked((int)0xa6322bdf),
unchecked((int)0xa2f33668),
unchecked((int)0xbcb4666d), unchecked((int)0xb8757bda), unchecked((int)0xb5365d03),
unchecked((int)0xb1f740b4)
};
public CRC()
{
@@ -170,7 +170,7 @@ namespace SharpCompress.Compressor.BZip2
internal void InitialiseCRC()
{
globalCrc = unchecked((int) 0xffffffff);
globalCrc = unchecked((int)0xffffffff);
}
internal int GetFinalCRC()
@@ -195,7 +195,7 @@ namespace SharpCompress.Compressor.BZip2
{
temp = 256 + temp;
}
globalCrc = (globalCrc << 8) ^ CRC.crc32Table[temp];
globalCrc = (globalCrc << 8) ^ crc32Table[temp];
}
internal int globalCrc;

View File

@@ -3,6 +3,6 @@
public enum CompressionMode
{
Compress = 0,
Decompress = 1,
Decompress = 1
}
}

View File

@@ -49,7 +49,6 @@ namespace SharpCompress.Compressor.Deflate
private const int BUFFER_SIZE = 8192;
private static readonly UInt32[] crc32Table;
private UInt32 runningCrc32Result = 0xFFFFFFFF;
private Int64 totalBytesRead;
static CRC32()
{
@@ -89,10 +88,7 @@ namespace SharpCompress.Compressor.Deflate
/// indicates the total number of bytes read on the CRC stream.
/// This is used when writing the ZipDirEntry when compressing files.
/// </summary>
public Int64 TotalBytesRead
{
get { return totalBytesRead; }
}
public Int64 TotalBytesRead { get; private set; }
/// <summary>
/// Indicates the current CRC for all blocks slurped in.
@@ -102,7 +98,7 @@ namespace SharpCompress.Compressor.Deflate
get
{
// return one's complement of the running result
return unchecked((Int32) (~runningCrc32Result));
return unchecked((Int32)(~runningCrc32Result));
}
}
@@ -126,7 +122,9 @@ namespace SharpCompress.Compressor.Deflate
public Int32 GetCrc32AndCopy(Stream input, Stream output)
{
if (input == null)
{
throw new ZlibException("The input stream must not be null.");
}
unchecked
{
@@ -135,23 +133,28 @@ namespace SharpCompress.Compressor.Deflate
var buffer = new byte[BUFFER_SIZE];
int readSize = BUFFER_SIZE;
totalBytesRead = 0;
TotalBytesRead = 0;
int count = input.Read(buffer, 0, readSize);
if (output != null) output.Write(buffer, 0, count);
totalBytesRead += count;
if (output != null)
{
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);
totalBytesRead += count;
if (output != null)
{
output.Write(buffer, 0, count);
}
TotalBytesRead += count;
}
return (Int32) (~runningCrc32Result);
return (Int32)(~runningCrc32Result);
}
}
/// <summary>
/// Get the CRC32 for the given (word,byte) combo. This is a computation
/// defined by PKzip.
@@ -161,12 +164,12 @@ namespace SharpCompress.Compressor.Deflate
/// <returns>The CRC-ized result.</returns>
public Int32 ComputeCrc32(Int32 W, byte B)
{
return _InternalComputeCrc32((UInt32) W, B);
return _InternalComputeCrc32((UInt32)W, B);
}
internal Int32 _InternalComputeCrc32(UInt32 W, byte B)
{
return (Int32) (crc32Table[(W ^ B) & 0xFF] ^ (W >> 8));
return (Int32)(crc32Table[(W ^ B) & 0xFF] ^ (W >> 8));
}
/// <summary>
@@ -179,7 +182,9 @@ namespace SharpCompress.Compressor.Deflate
public void SlurpBlock(byte[] block, int offset, int count)
{
if (block == null)
{
throw new ZlibException("The data buffer must not be null.");
}
for (int i = 0; i < count; i++)
{
@@ -187,13 +192,11 @@ namespace SharpCompress.Compressor.Deflate
runningCrc32Result = ((runningCrc32Result) >> 8) ^
crc32Table[(block[x]) ^ ((runningCrc32Result) & 0x000000FF)];
}
totalBytesRead += count;
TotalBytesRead += count;
}
// pre-initialize the crc table for speed of lookup.
private uint gf2_matrix_times(uint[] matrix, uint vec)
{
uint sum = 0;
@@ -201,7 +204,9 @@ namespace SharpCompress.Compressor.Deflate
while (vec != 0)
{
if ((vec & 0x01) == 0x01)
{
sum ^= matrix[i];
}
vec >>= 1;
i++;
}
@@ -211,10 +216,11 @@ namespace SharpCompress.Compressor.Deflate
private void gf2_matrix_square(uint[] square, uint[] mat)
{
for (int i = 0; i < 32; i++)
{
square[i] = gf2_matrix_times(mat, mat[i]);
}
}
/// <summary>
/// Combines the given CRC32 value with the current running total.
/// </summary>
@@ -231,10 +237,12 @@ namespace SharpCompress.Compressor.Deflate
var odd = new uint[32]; // odd-power-of-two zeros operator
if (length == 0)
{
return;
}
uint crc1 = ~runningCrc32Result;
var crc2 = (uint) crc;
var crc2 = (uint)crc;
// put operator for one zero bit in odd
odd[0] = 0xEDB88320; // the CRC-32 polynomial
@@ -251,7 +259,7 @@ namespace SharpCompress.Compressor.Deflate
// put operator for four zero bits in odd
gf2_matrix_square(odd, even);
var len2 = (uint) length;
var len2 = (uint)length;
// apply len2 zeros to crc1 (first square will put the operator for one
// zero byte, eight zero bits, in even)
@@ -261,28 +269,33 @@ namespace SharpCompress.Compressor.Deflate
gf2_matrix_square(even, odd);
if ((len2 & 1) == 1)
{
crc1 = gf2_matrix_times(even, crc1);
}
len2 >>= 1;
if (len2 == 0)
{
break;
}
// another iteration of the loop with odd and even swapped
gf2_matrix_square(odd, even);
if ((len2 & 1) == 1)
{
crc1 = gf2_matrix_times(odd, crc1);
}
len2 >>= 1;
} while (len2 != 0);
}
while (len2 != 0);
crc1 ^= crc2;
runningCrc32Result = ~crc1;
//return (int) crc1;
return;
}
// private member vars
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -35,7 +35,6 @@ namespace SharpCompress.Compressor.Deflate
private readonly ZlibBaseStream _baseStream;
private bool _disposed;
public DeflateStream(Stream stream, CompressionMode mode,
CompressionLevel level = CompressionLevel.Default,
bool leaveOpen = false)
@@ -55,7 +54,10 @@ namespace SharpCompress.Compressor.Deflate
get { return (_baseStream._flushMode); }
set
{
if (_disposed) throw new ObjectDisposedException("DeflateStream");
if (_disposed)
{
throw new ObjectDisposedException("DeflateStream");
}
_baseStream._flushMode = value;
}
}
@@ -82,13 +84,20 @@ namespace SharpCompress.Compressor.Deflate
get { return _baseStream._bufferSize; }
set
{
if (_disposed) throw new ObjectDisposedException("DeflateStream");
if (_disposed)
{
throw new ObjectDisposedException("DeflateStream");
}
if (_baseStream._workingBuffer != null)
{
throw new ZlibException("The working buffer is already set.");
}
if (value < ZlibConstants.WorkingBufferSizeMin)
{
throw new ZlibException(
String.Format("Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.", value,
ZlibConstants.WorkingBufferSizeMin));
String.Format("Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.", value,
ZlibConstants.WorkingBufferSizeMin));
}
_baseStream._bufferSize = value;
}
}
@@ -106,22 +115,19 @@ namespace SharpCompress.Compressor.Deflate
get { return _baseStream.Strategy; }
set
{
if (_disposed) throw new ObjectDisposedException("DeflateStream");
if (_disposed)
{
throw new ObjectDisposedException("DeflateStream");
}
_baseStream.Strategy = value;
}
}
/// <summary> Returns the total number of bytes input so far.</summary>
public virtual long TotalIn
{
get { return _baseStream._z.TotalBytesIn; }
}
public virtual long TotalIn { get { return _baseStream._z.TotalBytesIn; } }
/// <summary> Returns the total number of bytes output so far.</summary>
public virtual long TotalOut
{
get { return _baseStream._z.TotalBytesOut; }
}
public virtual long TotalOut { get { return _baseStream._z.TotalBytesOut; } }
#endregion
@@ -137,7 +143,10 @@ namespace SharpCompress.Compressor.Deflate
{
get
{
if (_disposed) throw new ObjectDisposedException("DeflateStream");
if (_disposed)
{
throw new ObjectDisposedException("DeflateStream");
}
return _baseStream._stream.CanRead;
}
}
@@ -148,11 +157,7 @@ namespace SharpCompress.Compressor.Deflate
/// <remarks>
/// Always returns false.
/// </remarks>
public override bool CanSeek
{
get { return false; }
}
public override bool CanSeek { get { return false; } }
/// <summary>
/// Indicates whether the stream can be written.
@@ -164,7 +169,10 @@ namespace SharpCompress.Compressor.Deflate
{
get
{
if (_disposed) throw new ObjectDisposedException("DeflateStream");
if (_disposed)
{
throw new ObjectDisposedException("DeflateStream");
}
return _baseStream._stream.CanWrite;
}
}
@@ -172,10 +180,7 @@ namespace SharpCompress.Compressor.Deflate
/// <summary>
/// Reading this property always throws a <see cref="NotImplementedException"/>.
/// </summary>
public override long Length
{
get { throw new NotSupportedException(); }
}
public override long Length { get { throw new NotSupportedException(); } }
/// <summary>
/// The position of the stream pointer.
@@ -193,9 +198,13 @@ namespace SharpCompress.Compressor.Deflate
get
{
if (_baseStream._streamMode == ZlibBaseStream.StreamMode.Writer)
{
return _baseStream._z.TotalBytesOut;
}
if (_baseStream._streamMode == ZlibBaseStream.StreamMode.Reader)
{
return _baseStream._z.TotalBytesIn;
}
return 0;
}
set { throw new NotSupportedException(); }
@@ -215,7 +224,9 @@ namespace SharpCompress.Compressor.Deflate
if (!_disposed)
{
if (disposing && (_baseStream != null))
{
_baseStream.Dispose();
}
_disposed = true;
}
}
@@ -230,7 +241,10 @@ namespace SharpCompress.Compressor.Deflate
/// </summary>
public override void Flush()
{
if (_disposed) throw new ObjectDisposedException("DeflateStream");
if (_disposed)
{
throw new ObjectDisposedException("DeflateStream");
}
_baseStream.Flush();
}
@@ -262,11 +276,13 @@ namespace SharpCompress.Compressor.Deflate
/// <returns>the number of bytes actually read</returns>
public override int Read(byte[] buffer, int offset, int count)
{
if (_disposed) throw new ObjectDisposedException("DeflateStream");
if (_disposed)
{
throw new ObjectDisposedException("DeflateStream");
}
return _baseStream.Read(buffer, offset, count);
}
/// <summary>
/// Calling this method always throws a <see cref="NotImplementedException"/>.
/// </summary>
@@ -318,7 +334,10 @@ namespace SharpCompress.Compressor.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("DeflateStream");
if (_disposed)
{
throw new ObjectDisposedException("DeflateStream");
}
_baseStream.Write(buffer, offset, count);
}

View File

@@ -39,6 +39,6 @@
Full,
/// <summary>Signals the end of the compression/decompression stream.</summary>
Finish,
Finish
}
}

View File

@@ -41,7 +41,6 @@ namespace SharpCompress.Compressor.Deflate
public DateTime? LastModified { get; set; }
private string comment;
private int crc32;
private string fileName;
internal ZlibBaseStream BaseStream;
@@ -49,7 +48,6 @@ namespace SharpCompress.Compressor.Deflate
private bool firstReadDone;
private int headerByteCount;
public GZipStream(Stream stream, CompressionMode mode)
: this(stream, mode, CompressionLevel.Default, false)
{
@@ -78,7 +76,9 @@ namespace SharpCompress.Compressor.Deflate
set
{
if (disposed)
{
throw new ObjectDisposedException("GZipStream");
}
BaseStream._flushMode = value;
}
}
@@ -89,27 +89,26 @@ namespace SharpCompress.Compressor.Deflate
set
{
if (disposed)
{
throw new ObjectDisposedException("GZipStream");
}
if (BaseStream._workingBuffer != null)
{
throw new ZlibException("The working buffer is already set.");
}
if (value < ZlibConstants.WorkingBufferSizeMin)
{
throw new ZlibException(
String.Format("Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.", value,
ZlibConstants.WorkingBufferSizeMin));
String.Format("Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.", value,
ZlibConstants.WorkingBufferSizeMin));
}
BaseStream._bufferSize = value;
}
}
internal virtual long TotalIn { get { return BaseStream._z.TotalBytesIn; } }
internal virtual long TotalIn
{
get { return BaseStream._z.TotalBytesIn; }
}
internal virtual long TotalOut
{
get { return BaseStream._z.TotalBytesOut; }
}
internal virtual long TotalOut { get { return BaseStream._z.TotalBytesOut; } }
#endregion
@@ -126,7 +125,9 @@ namespace SharpCompress.Compressor.Deflate
get
{
if (disposed)
{
throw new ObjectDisposedException("GZipStream");
}
return BaseStream._stream.CanRead;
}
}
@@ -137,11 +138,7 @@ namespace SharpCompress.Compressor.Deflate
/// <remarks>
/// Always returns false.
/// </remarks>
public override bool CanSeek
{
get { return false; }
}
public override bool CanSeek { get { return false; } }
/// <summary>
/// Indicates whether the stream can be written.
@@ -154,7 +151,9 @@ namespace SharpCompress.Compressor.Deflate
get
{
if (disposed)
{
throw new ObjectDisposedException("GZipStream");
}
return BaseStream._stream.CanWrite;
}
}
@@ -162,10 +161,7 @@ namespace SharpCompress.Compressor.Deflate
/// <summary>
/// Reading this property always throws a <see cref="NotImplementedException"/>.
/// </summary>
public override long Length
{
get { throw new NotSupportedException(); }
}
public override long Length { get { throw new NotSupportedException(); } }
/// <summary>
/// The position of the stream pointer.
@@ -183,9 +179,13 @@ namespace SharpCompress.Compressor.Deflate
get
{
if (BaseStream._streamMode == ZlibBaseStream.StreamMode.Writer)
{
return BaseStream._z.TotalBytesOut + headerByteCount;
}
if (BaseStream._streamMode == ZlibBaseStream.StreamMode.Reader)
{
return BaseStream._z.TotalBytesIn + BaseStream._gzipHeaderByteCount;
}
return 0;
}
@@ -208,7 +208,7 @@ namespace SharpCompress.Compressor.Deflate
if (disposing && (BaseStream != null))
{
BaseStream.Dispose();
crc32 = BaseStream.Crc32;
Crc32 = BaseStream.Crc32;
}
disposed = true;
}
@@ -225,7 +225,9 @@ namespace SharpCompress.Compressor.Deflate
public override void Flush()
{
if (disposed)
{
throw new ObjectDisposedException("GZipStream");
}
BaseStream.Flush();
}
@@ -263,7 +265,9 @@ namespace SharpCompress.Compressor.Deflate
public override int Read(byte[] buffer, int offset, int count)
{
if (disposed)
{
throw new ObjectDisposedException("GZipStream");
}
int n = BaseStream.Read(buffer, offset, count);
// Console.WriteLine("GZipStream::Read(buffer, off({0}), c({1}) = {2}", offset, count, n);
@@ -278,7 +282,6 @@ namespace SharpCompress.Compressor.Deflate
return n;
}
/// <summary>
/// Calling this method always throws a <see cref="NotImplementedException"/>.
/// </summary>
@@ -324,7 +327,9 @@ namespace SharpCompress.Compressor.Deflate
public override void Write(byte[] buffer, int offset, int count)
{
if (disposed)
{
throw new ObjectDisposedException("GZipStream");
}
if (BaseStream._streamMode == ZlibBaseStream.StreamMode.Undefined)
{
//Console.WriteLine("GZipStream: First write");
@@ -350,7 +355,9 @@ namespace SharpCompress.Compressor.Deflate
set
{
if (disposed)
{
throw new ObjectDisposedException("GZipStream");
}
comment = value;
}
}
@@ -361,16 +368,22 @@ namespace SharpCompress.Compressor.Deflate
set
{
if (disposed)
{
throw new ObjectDisposedException("GZipStream");
}
fileName = value;
if (fileName == null)
{
return;
}
if (fileName.IndexOf("/") != -1)
{
fileName = fileName.Replace("/", "\\");
}
if (fileName.EndsWith("\\"))
{
throw new InvalidOperationException("Illegal filename");
}
var index = fileName.IndexOf("\\");
if (index != -1)
@@ -390,11 +403,7 @@ namespace SharpCompress.Compressor.Deflate
}
}
public int Crc32
{
get { return crc32; }
}
public int Crc32 { get; private set; }
private int EmitHeader()
{
@@ -407,6 +416,7 @@ namespace SharpCompress.Compressor.Deflate
int bufferLength = 10 + cbLength + fnLength;
var header = new byte[bufferLength];
int i = 0;
// ID
header[i++] = 0x1F;
header[i++] = 0x8B;
@@ -415,23 +425,30 @@ namespace SharpCompress.Compressor.Deflate
header[i++] = 8;
byte flag = 0;
if (Comment != null)
{
flag ^= 0x10;
}
if (FileName != null)
{
flag ^= 0x8;
}
// flag
header[i++] = flag;
// mtime
if (!LastModified.HasValue)
{
LastModified = DateTime.Now;
}
TimeSpan delta = LastModified.Value - UnixEpoch;
var timet = (Int32) delta.TotalSeconds;
var timet = (Int32)delta.TotalSeconds;
DataConverter.LittleEndian.PutBytes(header, i, timet);
i += 4;
// xflg
header[i++] = 0; // this field is totally useless
// OS
header[i++] = 0xFF; // 0xFF == unspecified

View File

@@ -83,148 +83,148 @@ namespace SharpCompress.Compressor.Deflate
internal const int BMAX = 15; // maximum bit length of any code
//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[]
{
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
};
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
};
//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[]
{
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[]
{
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[]
{
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[]
{
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[]
{
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 int[] c; // bit length count table
@@ -268,7 +268,8 @@ namespace SharpCompress.Compressor.Deflate
c[b[bindex + p]]++;
p++;
i--; // assume all entries <= BMAX
} while (i != 0);
}
while (i != 0);
if (c[0] == n)
{
@@ -281,8 +282,12 @@ namespace SharpCompress.Compressor.Deflate
// Find minimum and maximum length, bound *m by those
l = m[0];
for (j = 1; j <= BMAX; j++)
{
if (c[j] != 0)
{
break;
}
}
k = j; // minimum code length
if (l < j)
{
@@ -291,7 +296,9 @@ namespace SharpCompress.Compressor.Deflate
for (i = BMAX; i != 0; i--)
{
if (c[i] != 0)
{
break;
}
}
g = i; // maximum code length
if (l > i)
@@ -336,7 +343,8 @@ namespace SharpCompress.Compressor.Deflate
v[x[j]++] = i;
}
p++;
} while (++i < n);
}
while (++i < n);
n = x[g]; // set n to length of v
// Generate the Huffman codes and for each, make the table entries
@@ -360,6 +368,7 @@ namespace SharpCompress.Compressor.Deflate
{
h++;
w += l; // previous table always l bits
// compute minimum size table less than or equal to l bits
z = g - w;
z = (z > l) ? l : z; // table size upper limit
@@ -375,7 +384,9 @@ namespace SharpCompress.Compressor.Deflate
{
// try smaller tables up to z bits
if ((f <<= 1) <= c[++xp])
{
break; // enough codes to use up j bits
}
f -= c[xp]; // else deduct codes from patterns
}
}
@@ -395,11 +406,11 @@ namespace SharpCompress.Compressor.Deflate
if (h != 0)
{
x[h] = i; // save pattern for backing up
r[0] = (sbyte) j; // bits in this table
r[1] = (sbyte) l; // bits to dump before this table
r[0] = (sbyte)j; // bits in this table
r[1] = (sbyte)l; // bits to dump before this table
j = SharedUtils.URShift(i, (w - l));
r[2] = (q - u[h - 1] - j); // offset to this table
Array.Copy(r, 0, hp, (u[h - 1] + j)*3, 3); // connect to last table
Array.Copy(r, 0, hp, (u[h - 1] + j) * 3, 3); // connect to last table
}
else
{
@@ -408,19 +419,19 @@ namespace SharpCompress.Compressor.Deflate
}
// set up table entry in r
r[1] = (sbyte) (k - w);
r[1] = (sbyte)(k - w);
if (p >= n)
{
r[0] = 128 + 64; // out of values--invalid code
}
else if (v[p] < s)
{
r[0] = (sbyte) (v[p] < 256 ? 0 : 32 + 64); // 256 is end-of-block
r[0] = (sbyte)(v[p] < 256 ? 0 : 32 + 64); // 256 is end-of-block
r[2] = v[p++]; // simple code is just the value
}
else
{
r[0] = (sbyte) (e[v[p] - s] + 16 + 64); // non-simple--look up in lists
r[0] = (sbyte)(e[v[p] - s] + 16 + 64); // non-simple--look up in lists
r[2] = d[v[p++] - s];
}
@@ -428,7 +439,7 @@ namespace SharpCompress.Compressor.Deflate
f = 1 << (k - w);
for (j = SharedUtils.URShift(i, w); j < z; j += f)
{
Array.Copy(r, 0, hp, (q + j)*3, 3);
Array.Copy(r, 0, hp, (q + j) * 3, 3);
}
// backwards increment the k-bit code i
@@ -448,6 +459,7 @@ namespace SharpCompress.Compressor.Deflate
}
}
}
// Return Z_BUF_ERROR if we were given an incomplete table
return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
}
@@ -551,9 +563,11 @@ namespace SharpCompress.Compressor.Deflate
r[0] = 0;
r[1] = 0;
r[2] = 0;
// for(int i=0; i<BMAX; i++){u[i]=0;}
//Array.Copy(c, 0, u, 0, BMAX);
Array.Clear(u, 0, BMAX);
// for(int i=0; i<BMAX+1; i++){x[i]=0;}
//Array.Copy(c, 0, x, 0, BMAX + 1);
Array.Clear(x, 0, BMAX + 1);

Some files were not shown because too many files have changed in this diff Show More