New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Filename field in GZip #351
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,77 @@ | ||
using System; | ||
using System.Text; | ||
|
||
namespace ICSharpCode.SharpZipLib.GZip | ||
{ | ||
/// <summary> | ||
/// This class contains constants used for gzip. | ||
/// </summary> | ||
sealed public class GZipConstants | ||
public static class GZipConstants | ||
{ | ||
/// <summary> | ||
/// Magic number found at start of GZIP header | ||
/// First GZip identification byte | ||
/// </summary> | ||
public const int GZIP_MAGIC = 0x1F8B; | ||
public const byte ID1 = 0x1F; | ||
|
||
/* The flag byte is divided into individual bits as follows: | ||
/// <summary> | ||
/// Second GZip identification byte | ||
/// </summary> | ||
public const byte ID2 = 0x8B; | ||
|
||
bit 0 FTEXT | ||
bit 1 FHCRC | ||
bit 2 FEXTRA | ||
bit 3 FNAME | ||
bit 4 FCOMMENT | ||
bit 5 reserved | ||
bit 6 reserved | ||
bit 7 reserved | ||
*/ | ||
/// <summary> | ||
/// Deflate compression method | ||
/// </summary> | ||
public const byte CompressionMethodDeflate = 0x8; | ||
|
||
/// <summary> | ||
/// Flag bit mask for text | ||
/// Get the GZip specified encoding (CP-1252 if supported, otherwise ASCII) | ||
/// </summary> | ||
public const int FTEXT = 0x1; | ||
public static Encoding Encoding | ||
{ | ||
get | ||
{ | ||
try | ||
{ | ||
return Encoding.GetEncoding(1252); | ||
} | ||
catch | ||
{ | ||
return Encoding.ASCII; | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
/// <summary> | ||
/// GZip header flags | ||
/// </summary> | ||
[Flags] | ||
public enum GZipFlags: byte | ||
{ | ||
/// <summary> | ||
/// Flag bitmask for Crc | ||
/// Text flag hinting that the file is in ASCII | ||
/// </summary> | ||
public const int FHCRC = 0x2; | ||
FTEXT = 0x1 << 0, | ||
|
||
/// <summary> | ||
/// Flag bit mask for extra | ||
/// CRC flag indicating that a CRC16 preceeds the data | ||
/// </summary> | ||
public const int FEXTRA = 0x4; | ||
FHCRC = 0x1 << 1, | ||
|
||
/// <summary> | ||
/// flag bitmask for name | ||
/// Extra flag indicating that extra fields are present | ||
/// </summary> | ||
public const int FNAME = 0x8; | ||
FEXTRA = 0x1 << 2, | ||
|
||
/// <summary> | ||
/// flag bit mask indicating comment is present | ||
/// Filename flag indicating that the original filename is present | ||
/// </summary> | ||
public const int FCOMMENT = 0x10; | ||
FNAME = 0x1 << 3, | ||
|
||
/// <summary> | ||
/// Initialise default instance. | ||
/// Flag bit mask indicating that a comment is present | ||
/// </summary> | ||
/// <remarks>Constructor is private to prevent instances being created.</remarks> | ||
private GZipConstants() | ||
{ | ||
} | ||
FCOMMENT = 0x1 << 4, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReadLeByte()
never returns anything but a byte, it will itself throw an exception in the case of an EOS