15 | return # exit script
16 | }
17 |
18 | # Else, build project with Coverity Scan.
19 | $publishCoverityExe = $env:APPVEYOR_BUILD_FOLDER + "\packages\PublishCoverity.0.11.0\tools\PublishCoverity.exe";
20 | "Building project with Coverity Scan..."
21 | & cov-build --dir Documentation\cov-int $buildCmd $buildArgs;
22 |
23 | # Compress scan data.
24 | & $publishCoverityExe compress -o Documentation\coverity.zip -i Documentation\cov-int;
25 |
26 | # Upload scan data.
27 | & $publishCoverityExe publish -z Documentation\coverity.zip -r McNeight/SharpZipLib -t $env:Coverity_Token -e $env:Coverity_Email -d "AppVeyor scheduled build";
28 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/vb/CreateZipFile/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/docs/opencover/ICSharpCode.SharpZipLib_ProgressHandler.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ICSharpCode.SharpZipLib.Core.ProgressHandler - Coverage Report
6 |
7 |
8 |
Summary
9 |
10 |
11 |
12 |
13 |
14 |
15 | Class: ICSharpCode.SharpZipLib.Core.ProgressHandler
16 | Assembly: ICSharpCode.SharpZipLib
17 | File(s):
18 | Covered lines: 0
19 | Uncovered lines: 0
20 | Coverable lines: 0
21 | Total lines: 0
22 | Line coverage:
23 |
24 |
25 |
File(s)
26 |
No files found. This usually happens if a file isn't covered by a test or the class does not contain any sequence points (e.g. a class that only contains auto properties).
27 |
28 |
29 |
--------------------------------------------------------------------------------
/test/ICSharpCode.SharpZipLib.Tests/ICSharpCode.SharpZipLib.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Library
5 | net6.0;net462
6 |
7 |
8 | true
9 | ..\..\assets\ICSharpCode.SharpZipLib.snk
10 | true
11 | 8.0
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | ICSharpCode.SharpZipLib.snk
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/cs/unzipfile/UnZipFile.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using ICSharpCode.SharpZipLib.Zip;
4 |
5 |
6 | class UnZipFileClass
7 | {
8 | public static void Main(string[] args)
9 | {
10 | // Perform simple parameter checking.
11 | if ( args.Length < 1 ) {
12 | Console.WriteLine("Usage UnzipFile NameOfFile");
13 | return;
14 | }
15 |
16 | if ( !File.Exists(args[0]) ) {
17 | Console.WriteLine("Cannot find file '{0}'", args[0]);
18 | return;
19 | }
20 |
21 | using (ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]))) {
22 |
23 | ZipEntry theEntry;
24 | while ((theEntry = s.GetNextEntry()) != null) {
25 |
26 | Console.WriteLine(theEntry.Name);
27 |
28 | string directoryName = Path.GetDirectoryName(theEntry.Name);
29 | string fileName = Path.GetFileName(theEntry.Name);
30 |
31 | // create directory
32 | if ( directoryName.Length > 0 ) {
33 | Directory.CreateDirectory(directoryName);
34 | }
35 |
36 | if (fileName != String.Empty) {
37 | using (FileStream streamWriter = File.Create(theEntry.Name)) {
38 |
39 | int size = 2048;
40 | byte[] data = new byte[2048];
41 | while (true) {
42 | size = s.Read(data, 0, data.Length);
43 | if (size > 0) {
44 | streamWriter.Write(data, 0, size);
45 | } else {
46 | break;
47 | }
48 | }
49 | }
50 | }
51 | }
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/docs/opencover/ICSharpCode.SharpZipLib_FileFailureHandler.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ICSharpCode.SharpZipLib.Core.FileFailureHandler - Coverage Report
6 |
7 |
8 |
Summary
9 |
10 |
11 |
12 |
13 |
14 |
15 | Class: ICSharpCode.SharpZipLib.Core.FileFailureHandler
16 | Assembly: ICSharpCode.SharpZipLib
17 | File(s):
18 | Covered lines: 0
19 | Uncovered lines: 0
20 | Coverable lines: 0
21 | Total lines: 0
22 | Line coverage:
23 |
24 |
25 |
File(s)
26 |
No files found. This usually happens if a file isn't covered by a test or the class does not contain any sequence points (e.g. a class that only contains auto properties).
27 |
28 |
29 |
--------------------------------------------------------------------------------
/docs/opencover/ICSharpCode.SharpZipLib_ProcessFileHandler.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ICSharpCode.SharpZipLib.Core.ProcessFileHandler - Coverage Report
6 |
7 |
8 |
Summary
9 |
10 |
11 |
12 |
13 |
14 |
15 | Class: ICSharpCode.SharpZipLib.Core.ProcessFileHandler
16 | Assembly: ICSharpCode.SharpZipLib
17 | File(s):
18 | Covered lines: 0
19 | Uncovered lines: 0
20 | Coverable lines: 0
21 | Total lines: 0
22 | Line coverage:
23 |
24 |
25 |
File(s)
26 |
No files found. This usually happens if a file isn't covered by a test or the class does not contain any sequence points (e.g. a class that only contains auto properties).
27 |
28 |
29 |
--------------------------------------------------------------------------------
/docs/opencover/ICSharpCode.SharpZipLib_CompletedFileHandler.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ICSharpCode.SharpZipLib.Core.CompletedFileHandler - Coverage Report
6 |
7 |
8 |
Summary
9 |
10 |
11 |
12 |
13 |
14 |
15 | Class: ICSharpCode.SharpZipLib.Core.CompletedFileHandler
16 | Assembly: ICSharpCode.SharpZipLib
17 | File(s):
18 | Covered lines: 0
19 | Uncovered lines: 0
20 | Coverable lines: 0
21 | Total lines: 0
22 | Line coverage:
23 |
24 |
25 |
File(s)
26 |
No files found. This usually happens if a file isn't covered by a test or the class does not contain any sequence points (e.g. a class that only contains auto properties).
27 |
28 |
29 |
--------------------------------------------------------------------------------
/docs/opencover/ICSharpCode.SharpZipLib_ZipTestResultHandler.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ICSharpCode.SharpZipLib.Zip.ZipTestResultHandler - Coverage Report
6 |
7 |
8 |
Summary
9 |
10 |
11 |
12 |
13 |
14 |
15 | Class: ICSharpCode.SharpZipLib.Zip.ZipTestResultHandler
16 | Assembly: ICSharpCode.SharpZipLib
17 | File(s):
18 | Covered lines: 0
19 | Uncovered lines: 0
20 | Coverable lines: 0
21 | Total lines: 0
22 | Line coverage:
23 |
24 |
25 |
File(s)
26 |
No files found. This usually happens if a file isn't covered by a test or the class does not contain any sequence points (e.g. a class that only contains auto properties).
27 |
28 |
29 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/vb/viewzipfile/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/docs/opencover/ICSharpCode.SharpZipLib_ProgressMessageHandler.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ICSharpCode.SharpZipLib.Tar.ProgressMessageHandler - Coverage Report
6 |
7 |
8 |
Summary
9 |
10 |
11 |
12 |
13 |
14 |
15 | Class: ICSharpCode.SharpZipLib.Tar.ProgressMessageHandler
16 | Assembly: ICSharpCode.SharpZipLib
17 | File(s):
18 | Covered lines: 0
19 | Uncovered lines: 0
20 | Coverable lines: 0
21 | Total lines: 0
22 | Line coverage:
23 |
24 |
25 |
File(s)
26 |
No files found. This usually happens if a file isn't covered by a test or the class does not contain any sequence points (e.g. a class that only contains auto properties).
27 |
28 |
29 |
--------------------------------------------------------------------------------
/docs/opencover/ICSharpCode.SharpZipLib_DirectoryFailureHandler.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ICSharpCode.SharpZipLib.Core.DirectoryFailureHandler - Coverage Report
6 |
7 |
8 |
Summary
9 |
10 |
11 |
12 |
13 |
14 |
15 | Class: ICSharpCode.SharpZipLib.Core.DirectoryFailureHandler
16 | Assembly: ICSharpCode.SharpZipLib
17 | File(s):
18 | Covered lines: 0
19 | Uncovered lines: 0
20 | Coverable lines: 0
21 | Total lines: 0
22 | Line coverage:
23 |
24 |
25 |
File(s)
26 |
No files found. This usually happens if a file isn't covered by a test or the class does not contain any sequence points (e.g. a class that only contains auto properties).
27 |
28 |
29 |
--------------------------------------------------------------------------------
/docs/future/FILEFMTS_GZIP.md:
--------------------------------------------------------------------------------
1 | --------A-GZIP------------------------------
2 | The GNU ZIP program is an archive program mostly for the UNIX machines developed
3 | by the GNU project.
4 | OFFSET Count TYPE Description
5 | 0000h 2 char ID='!',139
6 | 0002h 1 byte Method :
7 | 0-7 - reserved
8 | 8 - deflated
9 | 0003h 1 byte File flags :
10 | 0 - ASCII-text
11 | 1 - Multi-part file
12 | 2 - Name present
13 | 3 - Comment present
14 | 4 - Encrypted
15 | 5-8 - reserved
16 | 0004h 1 dword File date and time (see table 0009)
17 | 0008h 1 byte Extra flags
18 | 0009h 1 byte Target OS :
19 | 0 - DOS
20 | 1 - Amiga
21 | 2 - VMS
22 | 3 - Unix
23 | 4 - ????
24 | 5 - Atari
25 | 6 - OS/2
26 | 7 - MacOS
27 | 10 - TOPS-20
28 | 11 - Win/32
29 | EXTENSION:ZIP
30 | PROGRAMS:GNU gzip
31 |
--------------------------------------------------------------------------------
/benchmark/ICSharpCode.SharpZipLib.Benchmark/Zip/ZipInputStream.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using BenchmarkDotNet.Attributes;
3 |
4 | namespace ICSharpCode.SharpZipLib.Benchmark.Zip
5 | {
6 | [MemoryDiagnoser]
7 | [Config(typeof(MultipleRuntimes))]
8 | public class ZipInputStream
9 | {
10 | private const int ChunkCount = 64;
11 | private const int ChunkSize = 1024 * 1024;
12 | private const int N = ChunkCount * ChunkSize;
13 |
14 | byte[] zippedData;
15 | byte[] readBuffer = new byte[4096];
16 |
17 | [GlobalSetup]
18 | public void GlobalSetup()
19 | {
20 | using (var memoryStream = new MemoryStream())
21 | {
22 | using (var zipOutputStream = new SharpZipLib.Zip.ZipOutputStream(memoryStream))
23 | {
24 | zipOutputStream.PutNextEntry(new SharpZipLib.Zip.ZipEntry("0"));
25 |
26 | var inputBuffer = new byte[ChunkSize];
27 |
28 | for (int i = 0; i < ChunkCount; i++)
29 | {
30 | zipOutputStream.Write(inputBuffer, 0, inputBuffer.Length);
31 | }
32 | }
33 |
34 | zippedData = memoryStream.ToArray();
35 | }
36 | }
37 |
38 | [Benchmark]
39 | public long ReadZipInputStream()
40 | {
41 | using (var memoryStream = new MemoryStream(zippedData))
42 | {
43 | using (var zipInputStream = new SharpZipLib.Zip.ZipInputStream(memoryStream))
44 | {
45 | var entry = zipInputStream.GetNextEntry();
46 |
47 | while (zipInputStream.Read(readBuffer, 0, readBuffer.Length) > 0)
48 | {
49 |
50 | }
51 |
52 | return entry.Size;
53 | }
54 | }
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/Checksum/IChecksum.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ICSharpCode.SharpZipLib.Checksum
4 | {
5 | ///
6 | /// Interface to compute a data checksum used by checked input/output streams.
7 | /// A data checksum can be updated by one byte or with a byte array. After each
8 | /// update the value of the current checksum can be returned by calling
9 | /// getValue. The complete checksum object can also be reset
10 | /// so it can be used again with new data.
11 | ///
12 | public interface IChecksum
13 | {
14 | ///
15 | /// Resets the data checksum as if no update was ever called.
16 | ///
17 | void Reset();
18 |
19 | ///
20 | /// Returns the data checksum computed so far.
21 | ///
22 | long Value
23 | {
24 | get;
25 | }
26 |
27 | ///
28 | /// Adds one byte to the data checksum.
29 | ///
30 | ///
31 | /// the data value to add. The high byte of the int is ignored.
32 | ///
33 | void Update(int bval);
34 |
35 | ///
36 | /// Updates the data checksum with the bytes taken from the array.
37 | ///
38 | ///
39 | /// buffer an array of bytes
40 | ///
41 | void Update(byte[] buffer);
42 |
43 | ///
44 | /// Adds the byte array to the data checksum.
45 | ///
46 | ///
47 | /// The chunk of data to add
48 | ///
49 | void Update(ArraySegment segment);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.yml:
--------------------------------------------------------------------------------
1 | name: 💡 Feature request
2 | description: Have a new idea/feature ? Please suggest!
3 | labels: ["enhancement"]
4 | body:
5 | - type: textarea
6 | id: description
7 | attributes:
8 | label: Is your feature request related to a problem? Please describe.
9 | description: A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
10 | validations:
11 | required: true
12 |
13 | - type: textarea
14 | id: solution
15 | attributes:
16 | label: Describe the solution you'd like
17 | description: A clear and concise description of what you want to happen.
18 | validations:
19 | required: true
20 |
21 | - type: textarea
22 | id: alternatives
23 | attributes:
24 | label: Describe alternatives you've considered
25 | description: A clear and concise description of any alternative solutions or features you've considered.
26 | validations:
27 | required: true
28 |
29 | - id: tags
30 | type: dropdown
31 | attributes:
32 | label: Tags
33 | description: What areas are your feature request related to?
34 | multiple: true
35 | options:
36 | - ZIP
37 | - GZip
38 | - Tar
39 | - BZip2
40 | - Encoding
41 | - Encryption
42 | - Documentation
43 | - Async
44 | - Performance
45 |
46 | - type: textarea
47 | id: extrainfo
48 | attributes:
49 | label: Additional context
50 | description: Add any other context or screenshots about the feature request here.
51 | validations:
52 | required: false
53 |
--------------------------------------------------------------------------------
/docs/future/FILEFMTS_LZH.md:
--------------------------------------------------------------------------------
1 | LZH
2 | ===
3 |
4 | The LHArc/LHA archiver is a multi platform archiver made by Haruyasu Yoshizaki,
5 | which has a relatively good compression. It uses more or less the same
6 | technology like the ZIP programs by Phil Katz. There was a hack named "ICE",
7 | which had only the graphic characters displayed on decompression changed.
8 |
9 | ```
10 | OFFSET Count TYPE Description
11 | 0000h 1 byte Size of archived file header
12 | 0001h 1 byte Checksum of remaining bytes
13 | 0002h 3 char ID='-lh'
14 | ID='-lz'
15 | 0005h 1 char Compression methods used (see table 0005)
16 | 0006h 1 char ID='-'
17 | 0007h 1 dword Compressed size
18 | 000Bh 1 dword Uncompressed size
19 | 000Fh 1 dword Original file date/time (see table 0009)
20 | 0013h 1 word File attribute
21 | 0015h 1 byte Filename / path length in bytes
22 | ="LEN"
23 | 0016h "LEN" char Filename / path
24 | 0018h 1 word CRC-16 of original file
25 | +"LEN"
26 |
27 | (Table 0005)
28 | LHArc compression types
29 | "0" - No compression
30 | "1" - LZW, 4K buffer, Huffman for upper 6 bits of position
31 | "2" - unknown
32 | "3" - unknown
33 | "4" - LZW, Arithmetic Encoding
34 | "5" - LZW, Arithmetic Encoding
35 | "s" - LHa 2.x archive?
36 | "\" - LHa 2.x archive?
37 | "d" - LHa 2.x archive?
38 |
39 | EXTENSION:LZH,ICE
40 | OCCURENCES:PC
41 | PROGRAMS:LHArc.EXE, LHA.EXE
42 | ```
43 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/vb/WpfCreateZipFile/WpfCreateZipFileWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/docs/future/FILEFMTS_DWC.md:
--------------------------------------------------------------------------------
1 | DWC
2 | ===
3 |
4 | The DWC archives seem to be a relict from ancient computing times - I've never
5 | seen any program that dealt with them or could create them. They are yet
6 | included in this compilation for reasons I don't know. But maybe one of you
7 | stumbles over such a file, he might find this documentation helpful.
8 | The DWC archives consist of single file entries with one archive trailer. The
9 | archive entries seem to be at the start of the archive, but maybe they are
10 | stored at the end of the archive, before the trailer. Each file header has the
11 | following format :
12 |
13 | ```
14 | OFFSET Count TYPE Description
15 | 0000h 13 char Name of the original file in ASCIIZ.
16 | 000Dh 1 dword Size of the original file
17 | 0011h 1 dword MS-DOS date and time of the original file
18 | 0015h 1 dword Size of the compressed file
19 | 0019h 1 dword Offset of compressed data in archive file
20 | 001Dh 3 byte reserved
21 | 0020h 1 byte Method :
22 | 1 - crunched
23 | 2 - stored
24 |
25 | The trailer at the end of each archive has the following format :
26 | OFFSET Count TYPE Description
27 | 0000h 1 word Length of trailer (=27)
28 | 0002h 1 word Size of the directory entries (=34)??
29 | 0004h 16 byte reserved
30 | 0014h 1 dword Count of the directory entries
31 | 0018h 3 char ID="DWC"
32 |
33 | EXTENSION:DWC??
34 | OCCURENCES:PC??
35 | PROGRAMS:DWC.EXE??
36 | ```
37 |
--------------------------------------------------------------------------------
/benchmark/ICSharpCode.SharpZipLib.Benchmark/Zip/ZipOutputStream.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.Threading.Tasks;
3 | using BenchmarkDotNet.Attributes;
4 |
5 | namespace ICSharpCode.SharpZipLib.Benchmark.Zip
6 | {
7 | [MemoryDiagnoser]
8 | [Config(typeof(MultipleRuntimes))]
9 | public class ZipOutputStream
10 | {
11 | private const int ChunkCount = 64;
12 | private const int ChunkSize = 1024 * 1024;
13 | private const int N = ChunkCount * ChunkSize;
14 |
15 | byte[] outputBuffer;
16 | byte[] inputBuffer;
17 |
18 | [GlobalSetup]
19 | public void GlobalSetup()
20 | {
21 | inputBuffer = new byte[ChunkSize];
22 | outputBuffer = new byte[N];
23 | }
24 |
25 | [Benchmark]
26 | public long WriteZipOutputStream()
27 | {
28 | using (var memoryStream = new MemoryStream(outputBuffer))
29 | {
30 | var zipOutputStream = new SharpZipLib.Zip.ZipOutputStream(memoryStream);
31 | zipOutputStream.PutNextEntry(new SharpZipLib.Zip.ZipEntry("0"));
32 |
33 | for (int i = 0; i < ChunkCount; i++)
34 | {
35 | zipOutputStream.Write(inputBuffer, 0, inputBuffer.Length);
36 | }
37 |
38 | return memoryStream.Position;
39 | }
40 | }
41 |
42 | [Benchmark]
43 | public async Task WriteZipOutputStreamAsync()
44 | {
45 | using (var memoryStream = new MemoryStream(outputBuffer))
46 | {
47 | using (var zipOutputStream = new SharpZipLib.Zip.ZipOutputStream(memoryStream))
48 | {
49 | zipOutputStream.IsStreamOwner = false;
50 | zipOutputStream.PutNextEntry(new SharpZipLib.Zip.ZipEntry("0"));
51 |
52 | for (int i = 0; i < ChunkCount; i++)
53 | {
54 | await zipOutputStream.WriteAsync(inputBuffer, 0, inputBuffer.Length);
55 | }
56 | }
57 |
58 | return memoryStream.Position;
59 | }
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/vb/WpfCreateZipFile/My Project/AssemblyInfo.vb:
--------------------------------------------------------------------------------
1 | Imports System.Reflection
2 | Imports System.Resources
3 | Imports System.Runtime.InteropServices
4 |
5 | ' General Information about an assembly is controlled through the following
6 | ' set of attributes. Change these attribute values to modify the information
7 | ' associated with an assembly.
8 |
9 | ' Review the values of the assembly attributes
10 |
11 |
12 |
13 |
14 | 'In order to begin building localizable applications, set
15 | 'CultureYouAreCodingWith in your .vbproj file
16 | 'inside a . For example, if you are using US english
17 | 'in your source files, set the to "en-US". Then uncomment the
18 | 'NeutralResourceLanguage attribute below. Update the "en-US" in the line
19 | 'below to match the UICulture setting in the project file.
20 |
21 |
22 |
23 |
24 | 'The ThemeInfo attribute describes where any theme specific and generic resource dictionaries can be found.
25 | '1st parameter: where theme specific resource dictionaries are located
26 | '(used if a resource is not found in the page,
27 | ' or application resource dictionaries)
28 |
29 | '2nd parameter: where the generic resource dictionary is located
30 | '(used if a resource is not found in the page,
31 | 'app, and any theme specific resource dictionaries)
32 |
33 |
34 |
35 |
36 | 'The following GUID is for the ID of the typelib if this project is exposed to COM
37 |
38 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/Lzw/LzwConstants.cs:
--------------------------------------------------------------------------------
1 | namespace ICSharpCode.SharpZipLib.Lzw
2 | {
3 | ///
4 | /// This class contains constants used for LZW
5 | ///
6 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "kept for backwards compatibility")]
7 | sealed public class LzwConstants
8 | {
9 | ///
10 | /// Magic number found at start of LZW header: 0x1f 0x9d
11 | ///
12 | public const int MAGIC = 0x1f9d;
13 |
14 | ///
15 | /// Maximum number of bits per code
16 | ///
17 | public const int MAX_BITS = 16;
18 |
19 | /* 3rd header byte:
20 | * bit 0..4 Number of compression bits
21 | * bit 5 Extended header
22 | * bit 6 Free
23 | * bit 7 Block mode
24 | */
25 |
26 | ///
27 | /// Mask for 'number of compression bits'
28 | ///
29 | public const int BIT_MASK = 0x1f;
30 |
31 | ///
32 | /// Indicates the presence of a fourth header byte
33 | ///
34 | public const int EXTENDED_MASK = 0x20;
35 |
36 | //public const int FREE_MASK = 0x40;
37 |
38 | ///
39 | /// Reserved bits
40 | ///
41 | public const int RESERVED_MASK = 0x60;
42 |
43 | ///
44 | /// Block compression: if table is full and compression rate is dropping,
45 | /// clear the dictionary.
46 | ///
47 | public const int BLOCK_MODE_MASK = 0x80;
48 |
49 | ///
50 | /// LZW file header size (in bytes)
51 | ///
52 | public const int HDR_SIZE = 3;
53 |
54 | ///
55 | /// Initial number of bits per code
56 | ///
57 | public const int INIT_BITS = 9;
58 |
59 | private LzwConstants()
60 | {
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/Core/InflaterPool.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Concurrent;
3 | using ICSharpCode.SharpZipLib.Zip.Compression;
4 |
5 | namespace ICSharpCode.SharpZipLib.Core
6 | {
7 | ///
8 | /// Pool for instances as they can be costly due to byte array allocations.
9 | ///
10 | internal sealed class InflaterPool
11 | {
12 | private readonly ConcurrentQueue noHeaderPool = new ConcurrentQueue();
13 | private readonly ConcurrentQueue headerPool = new ConcurrentQueue();
14 |
15 | internal static InflaterPool Instance { get; } = new InflaterPool();
16 |
17 | private InflaterPool()
18 | {
19 | }
20 |
21 | internal Inflater Rent(bool noHeader = false)
22 | {
23 | if (SharpZipLibOptions.InflaterPoolSize <= 0)
24 | {
25 | return new Inflater(noHeader);
26 | }
27 |
28 | var pool = GetPool(noHeader);
29 |
30 | PooledInflater inf;
31 | if (pool.TryDequeue(out var inflater))
32 | {
33 | inf = inflater;
34 | inf.Reset();
35 | }
36 | else
37 | {
38 | inf = new PooledInflater(noHeader);
39 | }
40 |
41 | return inf;
42 | }
43 |
44 | internal void Return(Inflater inflater)
45 | {
46 | if (SharpZipLibOptions.InflaterPoolSize <= 0)
47 | {
48 | return;
49 | }
50 |
51 | if (!(inflater is PooledInflater pooledInflater))
52 | {
53 | throw new ArgumentException("Returned inflater was not a pooled one");
54 | }
55 |
56 | var pool = GetPool(inflater.noHeader);
57 | if (pool.Count < SharpZipLibOptions.InflaterPoolSize)
58 | {
59 | pooledInflater.Reset();
60 | pool.Enqueue(pooledInflater);
61 | }
62 | }
63 |
64 | private ConcurrentQueue GetPool(bool noHeader) => noHeader ? noHeaderPool : headerPool;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/Lzw/LzwException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.Serialization;
3 |
4 | namespace ICSharpCode.SharpZipLib.Lzw
5 | {
6 | ///
7 | /// LzwException represents exceptions specific to LZW classes and code.
8 | ///
9 | [Serializable]
10 | public class LzwException : SharpZipBaseException
11 | {
12 | ///
13 | /// Initialise a new instance of .
14 | ///
15 | public LzwException()
16 | {
17 | }
18 |
19 | ///
20 | /// Initialise a new instance of with its message string.
21 | ///
22 | /// A that describes the error.
23 | public LzwException(string message)
24 | : base(message)
25 | {
26 | }
27 |
28 | ///
29 | /// Initialise a new instance of .
30 | ///
31 | /// A that describes the error.
32 | /// The that caused this exception.
33 | public LzwException(string message, Exception innerException)
34 | : base(message, innerException)
35 | {
36 | }
37 |
38 | ///
39 | /// Initializes a new instance of the LzwException class with serialized data.
40 | ///
41 | ///
42 | /// The System.Runtime.Serialization.SerializationInfo that holds the serialized
43 | /// object data about the exception being thrown.
44 | ///
45 | ///
46 | /// The System.Runtime.Serialization.StreamingContext that contains contextual information
47 | /// about the source or destination.
48 | ///
49 | protected LzwException(SerializationInfo info, StreamingContext context)
50 | : base(info, context)
51 | {
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/Tar/TarException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.Serialization;
3 |
4 | namespace ICSharpCode.SharpZipLib.Tar
5 | {
6 | ///
7 | /// TarException represents exceptions specific to Tar classes and code.
8 | ///
9 | [Serializable]
10 | public class TarException : SharpZipBaseException
11 | {
12 | ///
13 | /// Initialise a new instance of .
14 | ///
15 | public TarException()
16 | {
17 | }
18 |
19 | ///
20 | /// Initialise a new instance of with its message string.
21 | ///
22 | /// A that describes the error.
23 | public TarException(string message)
24 | : base(message)
25 | {
26 | }
27 |
28 | ///
29 | /// Initialise a new instance of .
30 | ///
31 | /// A that describes the error.
32 | /// The that caused this exception.
33 | public TarException(string message, Exception innerException)
34 | : base(message, innerException)
35 | {
36 | }
37 |
38 | ///
39 | /// Initializes a new instance of the TarException class with serialized data.
40 | ///
41 | ///
42 | /// The System.Runtime.Serialization.SerializationInfo that holds the serialized
43 | /// object data about the exception being thrown.
44 | ///
45 | ///
46 | /// The System.Runtime.Serialization.StreamingContext that contains contextual information
47 | /// about the source or destination.
48 | ///
49 | protected TarException(SerializationInfo info, StreamingContext context)
50 | : base(info, context)
51 | {
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/Zip/ZipException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.Serialization;
3 |
4 | namespace ICSharpCode.SharpZipLib.Zip
5 | {
6 | ///
7 | /// ZipException represents exceptions specific to Zip classes and code.
8 | ///
9 | [Serializable]
10 | public class ZipException : SharpZipBaseException
11 | {
12 | ///
13 | /// Initialise a new instance of .
14 | ///
15 | public ZipException()
16 | {
17 | }
18 |
19 | ///
20 | /// Initialise a new instance of with its message string.
21 | ///
22 | /// A that describes the error.
23 | public ZipException(string message)
24 | : base(message)
25 | {
26 | }
27 |
28 | ///
29 | /// Initialise a new instance of .
30 | ///
31 | /// A that describes the error.
32 | /// The that caused this exception.
33 | public ZipException(string message, Exception innerException)
34 | : base(message, innerException)
35 | {
36 | }
37 |
38 | ///
39 | /// Initializes a new instance of the ZipException class with serialized data.
40 | ///
41 | ///
42 | /// The System.Runtime.Serialization.SerializationInfo that holds the serialized
43 | /// object data about the exception being thrown.
44 | ///
45 | ///
46 | /// The System.Runtime.Serialization.StreamingContext that contains contextual information
47 | /// about the source or destination.
48 | ///
49 | protected ZipException(SerializationInfo info, StreamingContext context)
50 | : base(info, context)
51 | {
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/GZip/GZipException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.Serialization;
3 |
4 | namespace ICSharpCode.SharpZipLib.GZip
5 | {
6 | ///
7 | /// GZipException represents exceptions specific to GZip classes and code.
8 | ///
9 | [Serializable]
10 | public class GZipException : SharpZipBaseException
11 | {
12 | ///
13 | /// Initialise a new instance of .
14 | ///
15 | public GZipException()
16 | {
17 | }
18 |
19 | ///
20 | /// Initialise a new instance of with its message string.
21 | ///
22 | /// A that describes the error.
23 | public GZipException(string message)
24 | : base(message)
25 | {
26 | }
27 |
28 | ///
29 | /// Initialise a new instance of .
30 | ///
31 | /// A that describes the error.
32 | /// The that caused this exception.
33 | public GZipException(string message, Exception innerException)
34 | : base(message, innerException)
35 | {
36 | }
37 |
38 | ///
39 | /// Initializes a new instance of the GZipException class with serialized data.
40 | ///
41 | ///
42 | /// The System.Runtime.Serialization.SerializationInfo that holds the serialized
43 | /// object data about the exception being thrown.
44 | ///
45 | ///
46 | /// The System.Runtime.Serialization.StreamingContext that contains contextual information
47 | /// about the source or destination.
48 | ///
49 | protected GZipException(SerializationInfo info, StreamingContext context)
50 | : base(info, context)
51 | {
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/BZip2/BZip2Exception.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.Serialization;
3 |
4 | namespace ICSharpCode.SharpZipLib.BZip2
5 | {
6 | ///
7 | /// BZip2Exception represents exceptions specific to BZip2 classes and code.
8 | ///
9 | [Serializable]
10 | public class BZip2Exception : SharpZipBaseException
11 | {
12 | ///
13 | /// Initialise a new instance of .
14 | ///
15 | public BZip2Exception()
16 | {
17 | }
18 |
19 | ///
20 | /// Initialise a new instance of with its message string.
21 | ///
22 | /// A that describes the error.
23 | public BZip2Exception(string message)
24 | : base(message)
25 | {
26 | }
27 |
28 | ///
29 | /// Initialise a new instance of .
30 | ///
31 | /// A that describes the error.
32 | /// The that caused this exception.
33 | public BZip2Exception(string message, Exception innerException)
34 | : base(message, innerException)
35 | {
36 | }
37 |
38 | ///
39 | /// Initializes a new instance of the BZip2Exception class with serialized data.
40 | ///
41 | ///
42 | /// The System.Runtime.Serialization.SerializationInfo that holds the serialized
43 | /// object data about the exception being thrown.
44 | ///
45 | ///
46 | /// The System.Runtime.Serialization.StreamingContext that contains contextual information
47 | /// about the source or destination.
48 | ///
49 | protected BZip2Exception(SerializationInfo info, StreamingContext context)
50 | : base(info, context)
51 | {
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/Tar/InvalidHeaderException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.Serialization;
3 |
4 | namespace ICSharpCode.SharpZipLib.Tar
5 | {
6 | ///
7 | /// This exception is used to indicate that there is a problem
8 | /// with a TAR archive header.
9 | ///
10 | [Serializable]
11 | public class InvalidHeaderException : TarException
12 | {
13 | ///
14 | /// Initialise a new instance of the InvalidHeaderException class.
15 | ///
16 | public InvalidHeaderException()
17 | {
18 | }
19 |
20 | ///
21 | /// Initialises a new instance of the InvalidHeaderException class with a specified message.
22 | ///
23 | /// Message describing the exception cause.
24 | public InvalidHeaderException(string message)
25 | : base(message)
26 | {
27 | }
28 |
29 | ///
30 | /// Initialise a new instance of InvalidHeaderException
31 | ///
32 | /// Message describing the problem.
33 | /// The exception that is the cause of the current exception.
34 | public InvalidHeaderException(string message, Exception exception)
35 | : base(message, exception)
36 | {
37 | }
38 |
39 | ///
40 | /// Initializes a new instance of the InvalidHeaderException class with serialized data.
41 | ///
42 | ///
43 | /// The System.Runtime.Serialization.SerializationInfo that holds the serialized
44 | /// object data about the exception being thrown.
45 | ///
46 | ///
47 | /// The System.Runtime.Serialization.StreamingContext that contains contextual information
48 | /// about the source or destination.
49 | ///
50 | protected InvalidHeaderException(SerializationInfo info, StreamingContext context)
51 | : base(info, context)
52 | {
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | # Workflow to execute when a new version is released
2 | name: Release
3 |
4 | on:
5 | release:
6 |
7 | # Used for testing and manual execution
8 | workflow_dispatch:
9 | inputs:
10 | tag:
11 | description: 'Tag Ref'
12 | required: true
13 |
14 | jobs:
15 | build:
16 | runs-on: windows-latest
17 | name: Generate DocFX documentation
18 | steps:
19 | - uses: actions/checkout@v3
20 | with:
21 | ref: ${{ github.events.inputs.tag }}
22 |
23 | - name: Setup .NET
24 | uses: actions/setup-dotnet@v1
25 | with:
26 | dotnet-version: '6.0.x'
27 |
28 | - name: Build project
29 | run: dotnet build -f netstandard2.0 src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj
30 |
31 | - name: Install docfx
32 | run: choco install docfx
33 |
34 | - name: Build Documentation
35 | run: docfx docs/help/docfx.json --warningsAsErrors
36 |
37 | - name: Upload documentation as artifact
38 | uses: actions/upload-artifact@v2
39 | with:
40 | name: site
41 | path: docs/help/_site
42 |
43 | deploy:
44 | needs: [build] # The second job must depend on the first one to complete before running and uses ubuntu-latest instead of windows.
45 | runs-on: ubuntu-latest
46 | name: Update github pages docs
47 | steps:
48 | - name: Checkout
49 | uses: actions/checkout@v3
50 |
51 | - name: Download Artifacts # The built project is downloaded into the 'site' folder.
52 | uses: actions/download-artifact@v1
53 | with:
54 | name: site
55 |
56 | - name: Publish documentation to Github Pages
57 | uses: JamesIves/github-pages-deploy-action@v4
58 | with:
59 | token: ${{ secrets.GITHUB_TOKEN }}
60 | branch: gh-pages
61 | folder: site
62 | target-folder: help
63 | clean: false
64 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/cs/viewzipfile/ViewZipFile.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Text;
4 | using ICSharpCode.SharpZipLib.Zip;
5 |
6 |
7 | class ViewZipFileClass
8 | {
9 | public static void Main(string[] args)
10 | {
11 | // Perform simple parameter checking.
12 | if ( args.Length < 1 ) {
13 | Console.WriteLine("Usage ViewZipFile NameOfFile");
14 | return;
15 | }
16 |
17 | if ( !File.Exists(args[0]) ) {
18 | Console.WriteLine("Cannot find file '{0}'", args[0]);
19 | return;
20 | }
21 |
22 | // For IO there should be exception handling but in this case its been ommitted
23 |
24 | byte[] data = new byte[4096];
25 |
26 | using (ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]))) {
27 |
28 | ZipEntry theEntry;
29 | while ((theEntry = s.GetNextEntry()) != null) {
30 | Console.WriteLine("Name : {0}", theEntry.Name);
31 | Console.WriteLine("Date : {0}", theEntry.DateTime);
32 | Console.WriteLine("Size : (-1, if the size information is in the footer)");
33 | Console.WriteLine(" Uncompressed : {0}", theEntry.Size);
34 | Console.WriteLine(" Compressed : {0}", theEntry.CompressedSize);
35 |
36 | if ( theEntry.IsFile ) {
37 |
38 | // Assuming the contents are text may be ok depending on what you are doing
39 | // here its fine as its shows how data can be read from a Zip archive.
40 | Console.Write("Show entry text (y/n) ?");
41 |
42 | if (Console.ReadLine() == "y") {
43 | int size = s.Read(data, 0, data.Length);
44 | while (size > 0) {
45 | Console.Write(Encoding.ASCII.GetString(data, 0, size));
46 | size = s.Read(data, 0, data.Length);
47 | }
48 | }
49 | Console.WriteLine();
50 | }
51 | }
52 |
53 | // Close can be ommitted as the using statement will do it automatically
54 | // but leaving it here reminds you that is should be done.
55 | s.Close();
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/benchmark/ICSharpCode.SharpZipLib.Benchmark/Zip/ZipFile.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Net.Http;
4 | using System.Threading.Tasks;
5 | using BenchmarkDotNet.Attributes;
6 | using ICSharpCode.SharpZipLib.Zip;
7 |
8 | namespace ICSharpCode.SharpZipLib.Benchmark.Zip
9 | {
10 | [MemoryDiagnoser]
11 | [Config(typeof(MultipleRuntimes))]
12 | public class ZipFile
13 | {
14 | private readonly byte[] readBuffer = new byte[4096];
15 | private string zipFileWithLargeAmountOfEntriesPath;
16 |
17 | [GlobalSetup]
18 | public async Task GlobalSetup()
19 | {
20 | SharpZipLibOptions.InflaterPoolSize = 4;
21 |
22 | // large real-world test file from test262 repository
23 | string commitSha = "2e4e0e6b8ebe3348a207144204cb6d7a5571c863";
24 | zipFileWithLargeAmountOfEntriesPath = Path.Combine(Path.GetTempPath(), $"{commitSha}.zip");
25 | if (!File.Exists(zipFileWithLargeAmountOfEntriesPath))
26 | {
27 | var uri = $"https://github.com/tc39/test262/archive/{commitSha}.zip";
28 |
29 | Console.WriteLine("Loading test262 repository archive from {0}", uri);
30 |
31 | using (var client = new HttpClient())
32 | {
33 | using (var downloadStream = await client.GetStreamAsync(uri))
34 | {
35 | using (var writeStream = File.OpenWrite(zipFileWithLargeAmountOfEntriesPath))
36 | {
37 | await downloadStream.CopyToAsync(writeStream);
38 | Console.WriteLine("File downloaded and saved to {0}", zipFileWithLargeAmountOfEntriesPath);
39 | }
40 | }
41 | }
42 | }
43 |
44 | }
45 |
46 | [Benchmark]
47 | public void ReadLargeZipFile()
48 | {
49 | using (var file = new SharpZipLib.Zip.ZipFile(zipFileWithLargeAmountOfEntriesPath))
50 | {
51 | foreach (ZipEntry entry in file)
52 | {
53 | using (var stream = file.GetInputStream(entry))
54 | {
55 | while (stream.Read(readBuffer, 0, readBuffer.Length) > 0)
56 | {
57 | }
58 | }
59 | }
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/docs/help/docfx.json:
--------------------------------------------------------------------------------
1 | {
2 | "metadata": [
3 | {
4 | "src": [
5 | {
6 | "cwd": "../../src/",
7 | "files": [
8 | "ICSharpCode.SharpZipLib/**.csproj"
9 | ],
10 | "exclude": [
11 | "**/obj/**",
12 | "**/bin/**",
13 | "_site/**"
14 | ]
15 | }
16 | ],
17 | "dest": "api",
18 | "properties": {
19 | "TargetFramework": "netstandard2.0"
20 | }
21 | }
22 | ],
23 | "build": {
24 | "content": [
25 | {
26 | "files": [
27 | "api/**.yml",
28 | "api/index.md"
29 | ]
30 | },
31 | {
32 | "files": [
33 | "articles/**.md",
34 | "articles/**/toc.yml",
35 | "toc.yml",
36 | "*.md"
37 | ],
38 | "exclude": [
39 | "obj/**",
40 | "_site/**"
41 | ]
42 | }
43 | ],
44 | "resource": [
45 | {
46 | "files": [
47 | "images/**"
48 | ],
49 | "exclude": [
50 | "obj/**",
51 | "_site/**"
52 | ]
53 | }
54 | ],
55 | "overwrite": [
56 | {
57 | "files": [
58 | "apidoc/**.md"
59 | ],
60 | "exclude": [
61 | "obj/**",
62 | "_site/**"
63 | ]
64 | }
65 | ],
66 | "globalMetadata": {
67 | "_appTitle": "SharpZipLib Help",
68 | "_appFooter": "Copyright © 2000-2022 SharpZipLib Contributors",
69 | "_gitContribute": {
70 | "repo": "https://github.com/icsharpcode/SharpZipLib",
71 | "branch": "master"
72 | }
73 | },
74 | "dest": "_site",
75 | "globalMetadataFiles": [],
76 | "fileMetadataFiles": [],
77 | "template": [
78 | "default",
79 | "template"
80 | ],
81 | "postProcessors": [],
82 | "noLangKeyword": false,
83 | "keepFileLink": false,
84 | "cleanupCacheHistory": false
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: csharp
2 | solution: ICSharpCode.SharpZipLib.sln
3 |
4 | #matrix:
5 | # include:
6 | # - mono: latest
7 | # - mono: none
8 | # env: NETCORE=1
9 | # dotnet: 2.1
10 | mono: none
11 | dotnet: 2.1
12 | os: linux
13 | install:
14 | - dotnet restore
15 | # - nuget restore ICSharpCode.SharpZipLib.sln
16 | # - nuget install NUnit.Console -Version 3.8.0 -OutputDirectory _testRunner
17 | script:
18 | - dotnet build -f netstandard2.0 src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj
19 | - dotnet run -c Debug -f netcoreapp2 -p test/ICSharpCode.SharpZipLib.TestBootstrapper/ICSharpCode.SharpZipLib.TestBootstrapper.csproj -- --where "class !~ WindowsNameTransformHandling & test !~ ZipEntryFactoryHandling.CreatedValues & test !~ ZipNameTransformHandling.FilenameCleaning" --result=docs/nunit3-test-results-debug.xml
20 | - dotnet run -c Release -f netcoreapp2 -p test/ICSharpCode.SharpZipLib.TestBootstrapper/ICSharpCode.SharpZipLib.TestBootstrapper.csproj -- --where "class !~ WindowsNameTransformHandling & test !~ ZipEntryFactoryHandling.CreatedValues & test !~ ZipNameTransformHandling.FilenameCleaning" --result=docs\nunit3-test-results-release.xml
21 | # - dotnet test test/ICSharpCode.SharpZipLib.Tests/ICSharpCode.SharpZipLib.Tests.csproj
22 | # - xbuild /p:Configuration=Release ICSharpCode.SharpZipLib.sln
23 | # - mono ./packages/NUnit.ConsoleRunner.3.2.1/tools/nunit3-console.exe --framework=mono-4.0 --labels=All --result=./Documentation/nunit3-test-results-travis.xml ./bin/Release/ICSharpCode.SharpZipLib.Tests.dll
24 | after_script:
25 | - dotnet pack -f netstandard2.0 -o _dist/ src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj
26 | #cache:
27 | # directories:
28 | # - bin
29 | # - Documentation
30 | #deploy:
31 | # provider: releases
32 | # api_key: "GITHUB OAUTH TOKEN"
33 | # file:
34 | # - "bin/Release/ICSharpCode.SharpZipLib.nupkg"
35 | # - "Documentation/nunit3-test-results-travis.xml"
36 | # skip_cleanup: true
37 | # on:
38 | # tags: true
39 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/GZip/GZipConstants.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 |
4 | namespace ICSharpCode.SharpZipLib.GZip
5 | {
6 | ///
7 | /// This class contains constants used for gzip.
8 | ///
9 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "kept for backwards compatibility")]
10 | sealed public class GZipConstants
11 | {
12 | ///
13 | /// First GZip identification byte
14 | ///
15 | public const byte ID1 = 0x1F;
16 |
17 | ///
18 | /// Second GZip identification byte
19 | ///
20 | public const byte ID2 = 0x8B;
21 |
22 | ///
23 | /// Deflate compression method
24 | ///
25 | public const byte CompressionMethodDeflate = 0x8;
26 |
27 | ///
28 | /// Get the GZip specified encoding (CP-1252 if supported, otherwise ASCII)
29 | ///
30 | public static Encoding Encoding
31 | {
32 | get
33 | {
34 | try
35 | {
36 | return Encoding.GetEncoding(1252);
37 | }
38 | catch
39 | {
40 | return Encoding.ASCII;
41 | }
42 | }
43 | }
44 |
45 | }
46 |
47 | ///
48 | /// GZip header flags
49 | ///
50 | [Flags]
51 | public enum GZipFlags: byte
52 | {
53 | ///
54 | /// Text flag hinting that the file is in ASCII
55 | ///
56 | FTEXT = 0x1 << 0,
57 |
58 | ///
59 | /// CRC flag indicating that a CRC16 preceeds the data
60 | ///
61 | FHCRC = 0x1 << 1,
62 |
63 | ///
64 | /// Extra flag indicating that extra fields are present
65 | ///
66 | FEXTRA = 0x1 << 2,
67 |
68 | ///
69 | /// Filename flag indicating that the original filename is present
70 | ///
71 | FNAME = 0x1 << 3,
72 |
73 | ///
74 | /// Flag bit mask indicating that a comment is present
75 | ///
76 | FCOMMENT = 0x1 << 4,
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/tools/old/ICSharpCode.SharpZipLib.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ICSharpCode.SharpZipLib-dogfood
5 | 1.0
6 | SharpZipLib-dogfood
7 | IC#Code
8 | IC#Code
9 | SharpZipLib (#ziplib, formerly NZipLib) is a compression library for Zip, GZip, BZip2, and Tar written entirely in C# for .NET. It is implemented as an assembly (installable in the GAC), and thus can easily be incorporated into other projects (in any .NET language)
10 | Please see https://github.com/icsharpcode/SharpZipLib/wiki/Release-1.0 for more information.
11 | "Dogfood" builds for testing purposes. Even *I* wouldn't put this code into production :)
12 | en-US
13 | http://icsharpcode.github.io/SharpZipLib/
14 |
15 | http://icsharpcode.github.io/SharpZipLib/#license
16 | Copyright © 2000-2016 SharpZipLib Contributors
17 | false
18 |
19 |
20 |
21 | Compression Library Zip GZip BZip2 LZW Tar
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/tools/appveyor-install.ps1:
--------------------------------------------------------------------------------
1 | # Describe from the lastest tag matching 'vX.Y.Z', removing the initial 'v'
2 | $description = $(git describe --long --tags --match 'v[0-9]*.[0-9]*.[0-9]*').substring(1);
3 |
4 | # Description is in the format of: TAG-COMMITS_SINCE_TAG-COMMIT_HASH
5 | $dparts = $description -split('-');
6 | $short_version = $dparts[0];
7 | $commits_since_tag = $dparts[1];
8 | $commit_hash = $dparts[2];
9 |
10 | $masterBranches = @("master");
11 |
12 | $is_tag_build = ($env:APPVEYOR_REPO_TAG -eq "true");
13 |
14 | # If not in master branch, set branch variable
15 | $av_branch = $env:APPVEYOR_REPO_BRANCH;
16 | $branch = $(if ($is_tag_build -or $masterBranches -contains $av_branch) { "" } else { "-$av_branch" });
17 |
18 | # If this is a PR, add the PR suffix
19 | $suffix = $(if ($env:APPVEYOR_PULL_REQUEST_NUMBER) { "-pr$env:APPVEYOR_PULL_REQUEST_NUMBER" } else { "" });
20 |
21 | # Main build is when we're in the master branch and not a PR
22 | $is_main_build = ($branch -eq "" -and $suffix -eq "")
23 |
24 | # Use appveyor build number as the last version digit (x.x.x.B)
25 | $build = ${env:APPVEYOR_BUILD_NUMBER}
26 |
27 | $is_release_build = ($commits_since_tag -eq 0 -and $is_main_build)
28 |
29 | $version = $(if ($is_release_build) { $short_version } else { "$short_version-$commit_hash" })
30 | $bin_version = "$short_version.$build"
31 |
32 | write-host -n "Branch: ";
33 | write-host -f cyan $av_branch;
34 |
35 | write-host -n "Release type: ";
36 | if ($is_release_build) {write-host -f green 'release'} else { write-host -f yellow 'pre-release'}
37 |
38 | write-host -n "NuGet Package Version: ";
39 | write-host -f cyan $version;
40 |
41 | write-host -n "Assembly Version: ";
42 | write-host -f cyan $bin_version;
43 |
44 | $av_version = "$bin_version$branch$suffix";
45 |
46 | $env:APPVEYOR_BUILD_VERSION=$av_version;
47 | $env:BIN_VERSION=$bin_version;
48 | $env:VERSION=$version;
49 |
50 | write-host -n "AppVeyor Build Version: ";
51 | write-host -f green $av_version;
52 |
53 | appveyor UpdateBuild -Version $av_version
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/Core/ExactMemoryPool.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Buffers;
3 |
4 | namespace ICSharpCode.SharpZipLib.Core
5 | {
6 | ///
7 | /// A MemoryPool that will return a Memory which is exactly the length asked for using the bufferSize parameter.
8 | /// This is in contrast to the default ArrayMemoryPool which will return a Memory of equal size to the underlying
9 | /// array which at least as long as the minBufferSize parameter.
10 | /// Note: The underlying array may be larger than the slice of Memory
11 | ///
12 | ///
13 | internal sealed class ExactMemoryPool : MemoryPool
14 | {
15 | public new static readonly MemoryPool Shared = new ExactMemoryPool();
16 |
17 | public override IMemoryOwner Rent(int bufferSize = -1)
18 | {
19 | if ((uint)bufferSize > int.MaxValue || bufferSize < 0)
20 | {
21 | throw new ArgumentOutOfRangeException(nameof(bufferSize));
22 | }
23 |
24 | return new ExactMemoryPoolBuffer(bufferSize);
25 | }
26 |
27 | protected override void Dispose(bool disposing)
28 | {
29 | }
30 |
31 | public override int MaxBufferSize => int.MaxValue;
32 |
33 | private sealed class ExactMemoryPoolBuffer : IMemoryOwner, IDisposable
34 | {
35 | private T[] array;
36 | private readonly int size;
37 |
38 | public ExactMemoryPoolBuffer(int size)
39 | {
40 | this.size = size;
41 | this.array = ArrayPool.Shared.Rent(size);
42 | }
43 |
44 | public Memory Memory
45 | {
46 | get
47 | {
48 | T[] array = this.array;
49 | if (array == null)
50 | {
51 | throw new ObjectDisposedException(nameof(ExactMemoryPoolBuffer));
52 | }
53 |
54 | return new Memory(array).Slice(0, size);
55 | }
56 | }
57 |
58 | public void Dispose()
59 | {
60 | T[] array = this.array;
61 | if (array == null)
62 | {
63 | return;
64 | }
65 |
66 | this.array = null;
67 | ArrayPool.Shared.Return(array);
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/benchmark/ICSharpCode.SharpZipLib.Benchmark/Tar/TarOutputStream.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.Security.Cryptography;
3 | using System.Text;
4 | using System.Threading;
5 | using System.Threading.Tasks;
6 | using BenchmarkDotNet.Attributes;
7 | using ICSharpCode.SharpZipLib.Tar;
8 |
9 | namespace ICSharpCode.SharpZipLib.Benchmark.Tar
10 | {
11 | [MemoryDiagnoser]
12 | [Config(typeof(MultipleRuntimes))]
13 | public class TarOutputStream
14 | {
15 | private readonly byte[] backingArray = new byte[1024 * 1024 + (6 * 1024)];
16 | private readonly byte[] inputBuffer = new byte[1024];
17 | private static readonly RandomNumberGenerator _rng = RandomNumberGenerator.Create();
18 |
19 | [Benchmark]
20 | public void WriteTarOutputStream()
21 | {
22 | using (var outputMemoryStream = new MemoryStream(backingArray))
23 | {
24 | using (var tarOutputStream =
25 | new ICSharpCode.SharpZipLib.Tar.TarOutputStream(outputMemoryStream, Encoding.UTF8))
26 | {
27 | var tarEntry = TarEntry.CreateTarEntry("some file");
28 | tarEntry.Size = 1024 * 1024;
29 | tarOutputStream.PutNextEntry(tarEntry);
30 |
31 | _rng.GetBytes(inputBuffer);
32 |
33 | for (int i = 0; i < 1024; i++)
34 | {
35 | tarOutputStream.Write(inputBuffer, 0, inputBuffer.Length);
36 | }
37 | }
38 | }
39 | }
40 |
41 | [Benchmark]
42 | public async Task WriteTarOutputStreamAsync()
43 | {
44 | using (var outputMemoryStream = new MemoryStream(backingArray))
45 | {
46 | using (var tarOutputStream =
47 | new ICSharpCode.SharpZipLib.Tar.TarOutputStream(outputMemoryStream, Encoding.UTF8))
48 | {
49 | var tarEntry = TarEntry.CreateTarEntry("some file");
50 | tarEntry.Size = 1024 * 1024;
51 |
52 | await tarOutputStream.PutNextEntryAsync(tarEntry, CancellationToken.None);
53 |
54 | _rng.GetBytes(inputBuffer);
55 |
56 | for (int i = 0; i < 1024; i++)
57 | {
58 | await tarOutputStream.WriteAsync(inputBuffer, 0, inputBuffer.Length);
59 | }
60 | }
61 | }
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/Core/InvalidNameException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.Serialization;
3 |
4 | namespace ICSharpCode.SharpZipLib.Core
5 | {
6 | ///
7 | /// InvalidNameException is thrown for invalid names such as directory traversal paths and names with invalid characters
8 | ///
9 | [Serializable]
10 | public class InvalidNameException : SharpZipBaseException
11 | {
12 | ///
13 | /// Initializes a new instance of the InvalidNameException class with a default error message.
14 | ///
15 | public InvalidNameException() : base("An invalid name was specified")
16 | {
17 | }
18 |
19 | ///
20 | /// Initializes a new instance of the InvalidNameException class with a specified error message.
21 | ///
22 | /// A message describing the exception.
23 | public InvalidNameException(string message) : base(message)
24 | {
25 | }
26 |
27 | ///
28 | /// Initializes a new instance of the InvalidNameException class with a specified
29 | /// error message and a reference to the inner exception that is the cause of this exception.
30 | ///
31 | /// A message describing the exception.
32 | /// The inner exception
33 | public InvalidNameException(string message, Exception innerException) : base(message, innerException)
34 | {
35 | }
36 |
37 | ///
38 | /// Initializes a new instance of the InvalidNameException class with serialized data.
39 | ///
40 | ///
41 | /// The System.Runtime.Serialization.SerializationInfo that holds the serialized
42 | /// object data about the exception being thrown.
43 | ///
44 | ///
45 | /// The System.Runtime.Serialization.StreamingContext that contains contextual information
46 | /// about the source or destination.
47 | ///
48 | protected InvalidNameException(SerializationInfo info, StreamingContext context)
49 | : base(info, context)
50 | {
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/docs/future/FILEFMTS_LBR.md:
--------------------------------------------------------------------------------
1 | LBR
2 | ===
3 |
4 | The LBR files consist of a direcotry and one or more "members". The directory
5 | contains from 4 to 256 entries and each entry describes one member.
6 | The first directory entry describes the directory itself. All space allocations
7 | are in terms of sectors, where a sector is 128 bytes long. Four directory
8 | entries fit in one sector thus the number of directory entries is always evenly
9 | divisible by 4. Different types of LBR files exist, all versions are discussed
10 | here, the directory entry looks like this :
11 |
12 | ```
13 | OFFSET Count TYPE Description
14 | 0000h 1 byte File status :
15 | 0 - active
16 | 254 - deleted
17 | 255 - free
18 | 0001h 11 char File name in FCB format (8/3, blank padded),
19 | directory name is blanks for old LU,
20 | ID='********DIR'
21 | for LUPC
22 | 000Ch 1 word Offset to file data in sectors
23 | 000Eh 1 word Length of stored data in sectors
24 |
25 | For the LUPC program, the remaining 16 bytes are used like this :
26 | OFFSET Count TYPE Description
27 | 0000h 8 char ASCII date of creation (MM/DD/YY)
28 | 0008h 8 char ASCII time of creation (HH:MM:SS)
29 |
30 | For the LU86 program, the remaining 16 bytes are used like this :
31 | OFFSET Count TYPE Description
32 | 0000h 1 word CRC-16 or 0
33 | 0002h 1 word Creation date in CP/M format
34 | 0004h 1 word Creation time in DOS format
35 | 0006h 1 word Date of last modification, CP/M format
36 | 0008h 1 word Time of last modification, DOS format
37 | 000Ah 1 byte Number of bytes in last sector
38 | 000Bh 5 byte reserved (0)
39 |
40 | EXTENSION:LBR
41 | OCCURENCES:PC,CP/M
42 | PROGRAMS:LU.COM, LUU.COM, LU86.COM
43 | SEE ALSO:
44 | ```
45 |
--------------------------------------------------------------------------------
/docs/future/FILEFMTS_ZOO.md:
--------------------------------------------------------------------------------
1 | --------A-ZOO-------------------------------
2 | The ZOO archive program by Raoul Dhesi is a file compression program now
3 | superceeded in both compression and speed by most other compression programs.
4 | The archive header looks like this :
5 | OFFSET Count TYPE Description
6 | 0000h 20 char Archive header text, ^Z terminated, null padded
7 | 0014h 1 dword ID=0FDC4A7DCh
8 | 0018h 1 dword Offset of first file in archive
9 | 001Ch 1 dword Offset of ????
10 | 0020h 1 byte Version archive was made by
11 | 0021h 1 byte Minimum version needed to extract
12 |
13 | Each stored file has its own header, which looks like this :
14 | OFFSET Count TYPE Description
15 | 0000h 1 dword ID=0FDC4A7DCh
16 | 0004h 1 byte Type of directory entry
17 | 0005h 1 byte Compression method :
18 | 0 - stored
19 | 1 - Crunched : LZW, 4K buffer,
20 | var len (9-13 bits)
21 | 0006h 1 dword Offset of next directory entry
22 | 000Ah 1 dword Offset of next header
23 | 000Dh 1 word Original date / time of file (see table 0009)
24 | 0012h 1 word CRC-16 of file
25 | 0014h 1 dword Uncompressed size of file
26 | 0018h 1 dword Compressed size of file
27 | 001Ch 1 byte Version this file was compressed by
28 | 001Dh 1 byte Minimum version needed to extract
29 | 001Eh 1 byte Deleted flag
30 | 0 - file in archive
31 | 1 - file is considered deleted
32 | 001Fh 1 dword Offset of comment field, 0 if none
33 | 0023h 1 word Length of comment field
34 | 0025h ? char ASCIIZ path / filename
35 |
36 | EXTENSION:ZOO
37 | OCCURENCES:PC
38 | PROGRAMS:ZOO.EXE
39 | REFERENCE:
40 | VALIDATION:
41 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/Core/Exceptions/StreamDecodingException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.Serialization;
3 |
4 | namespace ICSharpCode.SharpZipLib
5 | {
6 | ///
7 | /// Indicates that an error occurred during decoding of a input stream due to corrupt
8 | /// data or (unintentional) library incompatibility.
9 | ///
10 | [Serializable]
11 | public class StreamDecodingException : SharpZipBaseException
12 | {
13 | private const string GenericMessage = "Input stream could not be decoded";
14 |
15 | ///
16 | /// Initializes a new instance of the StreamDecodingException with a generic message
17 | ///
18 | public StreamDecodingException() : base(GenericMessage) { }
19 |
20 | ///
21 | /// Initializes a new instance of the StreamDecodingException class with a specified error message.
22 | ///
23 | /// A message describing the exception.
24 | public StreamDecodingException(string message) : base(message) { }
25 |
26 | ///
27 | /// Initializes a new instance of the StreamDecodingException class with a specified
28 | /// error message and a reference to the inner exception that is the cause of this exception.
29 | ///
30 | /// A message describing the exception.
31 | /// The inner exception
32 | public StreamDecodingException(string message, Exception innerException) : base(message, innerException) { }
33 |
34 | ///
35 | /// Initializes a new instance of the StreamDecodingException class with serialized data.
36 | ///
37 | ///
38 | /// The System.Runtime.Serialization.SerializationInfo that holds the serialized
39 | /// object data about the exception being thrown.
40 | ///
41 | ///
42 | /// The System.Runtime.Serialization.StreamingContext that contains contextual information
43 | /// about the source or destination.
44 | ///
45 | protected StreamDecodingException(SerializationInfo info, StreamingContext context)
46 | : base(info, context)
47 | {
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/Core/Exceptions/StreamUnsupportedException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.Serialization;
3 |
4 | namespace ICSharpCode.SharpZipLib
5 | {
6 | ///
7 | /// Indicates that the input stream could not decoded due to known library incompability or missing features
8 | ///
9 | [Serializable]
10 | public class StreamUnsupportedException : StreamDecodingException
11 | {
12 | private const string GenericMessage = "Input stream is in a unsupported format";
13 |
14 | ///
15 | /// Initializes a new instance of the StreamUnsupportedException with a generic message
16 | ///
17 | public StreamUnsupportedException() : base(GenericMessage) { }
18 |
19 | ///
20 | /// Initializes a new instance of the StreamUnsupportedException class with a specified error message.
21 | ///
22 | /// A message describing the exception.
23 | public StreamUnsupportedException(string message) : base(message) { }
24 |
25 | ///
26 | /// Initializes a new instance of the StreamUnsupportedException class with a specified
27 | /// error message and a reference to the inner exception that is the cause of this exception.
28 | ///
29 | /// A message describing the exception.
30 | /// The inner exception
31 | public StreamUnsupportedException(string message, Exception innerException) : base(message, innerException) { }
32 |
33 | ///
34 | /// Initializes a new instance of the StreamUnsupportedException class with serialized data.
35 | ///
36 | ///
37 | /// The System.Runtime.Serialization.SerializationInfo that holds the serialized
38 | /// object data about the exception being thrown.
39 | ///
40 | ///
41 | /// The System.Runtime.Serialization.StreamingContext that contains contextual information
42 | /// about the source or destination.
43 | ///
44 | protected StreamUnsupportedException(SerializationInfo info, StreamingContext context)
45 | : base(info, context)
46 | {
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/Core/Exceptions/UnexpectedEndOfStreamException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.Serialization;
3 |
4 | namespace ICSharpCode.SharpZipLib
5 | {
6 | ///
7 | /// Indicates that the input stream could not decoded due to the stream ending before enough data had been provided
8 | ///
9 | [Serializable]
10 | public class UnexpectedEndOfStreamException : StreamDecodingException
11 | {
12 | private const string GenericMessage = "Input stream ended unexpectedly";
13 |
14 | ///
15 | /// Initializes a new instance of the UnexpectedEndOfStreamException with a generic message
16 | ///
17 | public UnexpectedEndOfStreamException() : base(GenericMessage) { }
18 |
19 | ///
20 | /// Initializes a new instance of the UnexpectedEndOfStreamException class with a specified error message.
21 | ///
22 | /// A message describing the exception.
23 | public UnexpectedEndOfStreamException(string message) : base(message) { }
24 |
25 | ///
26 | /// Initializes a new instance of the UnexpectedEndOfStreamException class with a specified
27 | /// error message and a reference to the inner exception that is the cause of this exception.
28 | ///
29 | /// A message describing the exception.
30 | /// The inner exception
31 | public UnexpectedEndOfStreamException(string message, Exception innerException) : base(message, innerException) { }
32 |
33 | ///
34 | /// Initializes a new instance of the UnexpectedEndOfStreamException class with serialized data.
35 | ///
36 | ///
37 | /// The System.Runtime.Serialization.SerializationInfo that holds the serialized
38 | /// object data about the exception being thrown.
39 | ///
40 | ///
41 | /// The System.Runtime.Serialization.StreamingContext that contains contextual information
42 | /// about the source or destination.
43 | ///
44 | protected UnexpectedEndOfStreamException(SerializationInfo info, StreamingContext context)
45 | : base(info, context)
46 | {
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/Core/Exceptions/SharpZipBaseException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.Serialization;
3 |
4 | namespace ICSharpCode.SharpZipLib
5 | {
6 | ///
7 | /// SharpZipBaseException is the base exception class for SharpZipLib.
8 | /// All library exceptions are derived from this.
9 | ///
10 | /// NOTE: Not all exceptions thrown will be derived from this class.
11 | /// A variety of other exceptions are possible for example
12 | [Serializable]
13 | public class SharpZipBaseException : Exception
14 | {
15 | ///
16 | /// Initializes a new instance of the SharpZipBaseException class.
17 | ///
18 | public SharpZipBaseException()
19 | {
20 | }
21 |
22 | ///
23 | /// Initializes a new instance of the SharpZipBaseException class with a specified error message.
24 | ///
25 | /// A message describing the exception.
26 | public SharpZipBaseException(string message)
27 | : base(message)
28 | {
29 | }
30 |
31 | ///
32 | /// Initializes a new instance of the SharpZipBaseException class with a specified
33 | /// error message and a reference to the inner exception that is the cause of this exception.
34 | ///
35 | /// A message describing the exception.
36 | /// The inner exception
37 | public SharpZipBaseException(string message, Exception innerException)
38 | : base(message, innerException)
39 | {
40 | }
41 |
42 | ///
43 | /// Initializes a new instance of the SharpZipBaseException class with serialized data.
44 | ///
45 | ///
46 | /// The System.Runtime.Serialization.SerializationInfo that holds the serialized
47 | /// object data about the exception being thrown.
48 | ///
49 | ///
50 | /// The System.Runtime.Serialization.StreamingContext that contains contextual information
51 | /// about the source or destination.
52 | ///
53 | protected SharpZipBaseException(SerializationInfo info, StreamingContext context)
54 | : base(info, context)
55 | {
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/test/ICSharpCode.SharpZipLib.Tests/Core/StringBuilderPoolTests.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using ICSharpCode.SharpZipLib.Core;
4 | using NUnit.Framework;
5 |
6 | namespace ICSharpCode.SharpZipLib.Tests.Core
7 | {
8 | [TestFixture]
9 | public class StringBuilderPoolTests
10 | {
11 | [Test]
12 | [Category("Core")]
13 | public void RoundTrip()
14 | {
15 | var pool = new StringBuilderPool();
16 | var builder1 = pool.Rent();
17 | pool.Return(builder1);
18 | var builder2 = pool.Rent();
19 | Assert.AreEqual(builder1, builder2);
20 | }
21 |
22 | [Test]
23 | [Category("Core")]
24 | public void ReturnsClears()
25 | {
26 | var pool = new StringBuilderPool();
27 | var builder1 = pool.Rent();
28 | builder1.Append("Hello");
29 | pool.Return(builder1);
30 | Assert.AreEqual(0, builder1.Length);
31 | }
32 |
33 | [Test]
34 | [Category("Core")]
35 | public async Task ThreadSafeAsync()
36 | {
37 | // use a lot of threads to increase the likelihood of errors
38 | var concurrency = 100;
39 |
40 | var pool = new StringBuilderPool();
41 | var gate = new TaskCompletionSource();
42 | var startedTasks = new Task[concurrency];
43 | var completedTasks = new Task[concurrency];
44 | for (int i = 0; i < concurrency; i++)
45 | {
46 | var started = new TaskCompletionSource();
47 | startedTasks[i] = started.Task;
48 | var captured = i;
49 | completedTasks[i] = Task.Run(async () =>
50 | {
51 | started.SetResult(true);
52 | await gate.Task;
53 | var builder = pool.Rent();
54 | builder.Append("Hello ");
55 | builder.Append(captured);
56 | var str = builder.ToString();
57 | pool.Return(builder);
58 | return str;
59 | });
60 | }
61 |
62 | // make sure all the threads have started
63 | await Task.WhenAll(startedTasks);
64 |
65 | // let them all loose at the same time
66 | gate.SetResult(true);
67 |
68 | // make sure every thread produces the expected string and hence had its own StringBuilder
69 | var results = await Task.WhenAll(completedTasks);
70 | for (int i = 0; i < concurrency; i++)
71 | {
72 | var result = results[i];
73 | Assert.AreEqual($"Hello {i}", result);
74 | }
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/Core/PathUtils.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Linq;
4 |
5 | namespace ICSharpCode.SharpZipLib.Core
6 | {
7 | ///
8 | /// PathUtils provides simple utilities for handling paths.
9 | ///
10 | public static class PathUtils
11 | {
12 | ///
13 | /// Remove any path root present in the path
14 | ///
15 | /// A containing path information.
16 | /// The path with the root removed if it was present; path otherwise.
17 | public static string DropPathRoot(string path)
18 | {
19 | // No need to drop anything
20 | if (path == string.Empty) return path;
21 |
22 | var invalidChars = Path.GetInvalidPathChars();
23 | // If the first character after the root is a ':', .NET < 4.6.2 throws
24 | var cleanRootSep = path.Length >= 3 && path[1] == ':' && path[2] == ':';
25 |
26 | // Replace any invalid path characters with '_' to prevent Path.GetPathRoot from throwing.
27 | // Only pass the first 258 (should be 260, but that still throws for some reason) characters
28 | // as .NET < 4.6.2 throws on longer paths
29 | var cleanPath = new string(path.Take(258)
30 | .Select( (c, i) => invalidChars.Contains(c) || (i == 2 && cleanRootSep) ? '_' : c).ToArray());
31 |
32 | var stripLength = Path.GetPathRoot(cleanPath)?.Length ?? 0;
33 | while (path.Length > stripLength && (path[stripLength] == '/' || path[stripLength] == '\\')) stripLength++;
34 | return path.Substring(stripLength);
35 | }
36 |
37 | ///
38 | /// Returns a random file name in the users temporary directory, or in directory of if specified
39 | ///
40 | /// If specified, used as the base file name for the temporary file
41 | /// Returns a temporary file name
42 | public static string GetTempFileName(string original = null)
43 | {
44 | string fileName;
45 | var tempPath = Path.GetTempPath();
46 |
47 | do
48 | {
49 | fileName = original == null
50 | ? Path.Combine(tempPath, Path.GetRandomFileName())
51 | : $"{original}.{Path.GetRandomFileName()}";
52 | } while (File.Exists(fileName));
53 |
54 | return fileName;
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/docs/future/FILEFMTS_HA.md:
--------------------------------------------------------------------------------
1 | --------A-HA--------------------------------
2 | HA files (not to be confused with HamarSoft's HAP files [3]) contain a
3 | small archive header with a word count of the number of files in the
4 | archive. The constituent files stored sequentially with a header followed
5 | by the compressed data, as is with most archives.
6 |
7 | The main file header is formatted as follows:
8 | OFFSET Count TYPE Description
9 | 0000h 2 char ID='HA'
10 | 0002h 1 word Number of files in archive
11 |
12 | Every compressed file has a header before it, like this :
13 |
14 | OFFSET Count TYPE Description
15 | 0000h 1 byte Version & compression type
16 | 0001h 1 dword Compressed file size
17 | 0005h 1 dword Original file size
18 | 0009h 1 dword CCITT CRC-32 (same as ZModem/PkZIP)
19 | 000Dh 1 dword File time-stamp (Unix format)
20 | ? ? char ASCIIZ pathname
21 | ? ? char ASCIIZ filename
22 | ????h 1 byte Length of machine specific information
23 | ? byte Machine specific information
24 |
25 | Note that the path separator for pathnames is the 0FFh (255) character.
26 |
27 | The high nybble of the version & compression type field contains the
28 | version information (0=HA 0.98), the low nybble is the compression type :
29 |
30 | (Table 0012)
31 | HA compression types
32 | 0 "CPY" File is stored (no compression)
33 | 1 "ASC" Default compression method, using a sliding
34 | window dictionary with an arithmetic coder.
35 | 2 "HSC" Compression using a "finite context [sic]
36 | model and arithmetic coder"
37 | 14 "DIR" Directory entry
38 | 15 "SPECIAL" Used with HA 0.99B (?)
39 |
40 |
41 | Machine specific information known:
42 |
43 | 1 byte Machine type (Host-OS)
44 |
45 | 1 = MS DOS
46 | 2 = Linux (Unix)
47 |
48 | ? bytes Information (currently only file-attribute info)
49 |
50 | EXTENSION:HA
51 | OCCURENCES:PC, Linux
52 | PROGRAMS:HA
53 | REFERENCE:
54 |
--------------------------------------------------------------------------------
/benchmark/ICSharpCode.SharpZipLib.Benchmark/Tar/TarInputStream.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Security.Cryptography;
4 | using System.Text;
5 | using System.Threading;
6 | using System.Threading.Tasks;
7 | using BenchmarkDotNet.Attributes;
8 | using ICSharpCode.SharpZipLib.Tar;
9 |
10 | namespace ICSharpCode.SharpZipLib.Benchmark.Tar
11 | {
12 | [MemoryDiagnoser]
13 | [Config(typeof(MultipleRuntimes))]
14 | public class TarInputStream
15 | {
16 | private readonly byte[] archivedData;
17 | private readonly byte[] readBuffer = new byte[1024];
18 |
19 | public TarInputStream()
20 | {
21 | using (var outputMemoryStream = new MemoryStream())
22 | {
23 | using (var zipOutputStream =
24 | new ICSharpCode.SharpZipLib.Tar.TarOutputStream(outputMemoryStream, Encoding.UTF8))
25 | {
26 | var tarEntry = TarEntry.CreateTarEntry("some file");
27 | tarEntry.Size = 1024 * 1024;
28 | zipOutputStream.PutNextEntry(tarEntry);
29 |
30 | var rng = RandomNumberGenerator.Create();
31 | var inputBuffer = new byte[1024];
32 | rng.GetBytes(inputBuffer);
33 |
34 | for (int i = 0; i < 1024; i++)
35 | {
36 | zipOutputStream.Write(inputBuffer, 0, inputBuffer.Length);
37 | }
38 | }
39 |
40 | archivedData = outputMemoryStream.ToArray();
41 | }
42 | }
43 |
44 | [Benchmark]
45 | public long ReadTarInputStream()
46 | {
47 | using (var memoryStream = new MemoryStream(archivedData))
48 | using (var zipInputStream = new ICSharpCode.SharpZipLib.Tar.TarInputStream(memoryStream, Encoding.UTF8))
49 | {
50 | var entry = zipInputStream.GetNextEntry();
51 |
52 | while (zipInputStream.Read(readBuffer, 0, readBuffer.Length) > 0)
53 | {
54 | }
55 |
56 | return entry.Size;
57 | }
58 | }
59 |
60 | [Benchmark]
61 | public async Task ReadTarInputStreamAsync()
62 | {
63 | using (var memoryStream = new MemoryStream(archivedData))
64 | using (var zipInputStream = new ICSharpCode.SharpZipLib.Tar.TarInputStream(memoryStream, Encoding.UTF8))
65 | {
66 | var entry = await zipInputStream.GetNextEntryAsync(CancellationToken.None);
67 |
68 | #if NETCOREAPP2_1_OR_GREATER
69 | while (await zipInputStream.ReadAsync(readBuffer.AsMemory()) > 0)
70 | {
71 | }
72 | #else
73 | while (await zipInputStream.ReadAsync(readBuffer, 0, readBuffer.Length) > 0)
74 | {
75 | }
76 | #endif
77 |
78 | return entry.Size;
79 | }
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/vb/WpfCreateZipFile/WpfCreateZipFileWindow.xaml.vb:
--------------------------------------------------------------------------------
1 | Imports System.IO
2 | Imports ICSharpCode.SharpZipLib.Core
3 | Imports ICSharpCode.SharpZipLib.Zip
4 | Imports WpfFolderBrowser
5 |
6 |
7 | Class WpfCreateZipFileWindow
8 | Public Sub New()
9 | ' This call is required by the designer.
10 | InitializeComponent()
11 | ' Add any initialization after the InitializeComponent() call.
12 | End Sub
13 |
14 | Private Sub btnZipIt_Click(sender As Object, e As RoutedEventArgs) Handles btnZipIt.Click
15 | Dim sourceDir As String = tbSourceDir.Text.Trim()
16 |
17 | ' Simple sanity checks
18 | If sourceDir.Length = 0 Then
19 | MessageBox.Show("Please specify a directory")
20 | Return
21 | Else
22 | If Not Directory.Exists(sourceDir) Then
23 | MessageBox.Show(sourceDir, "Directory not found")
24 | Return
25 | End If
26 | End If
27 |
28 | Dim targetName As String = tbZipFileName.Text.Trim()
29 | If targetName.Length = 0 Then
30 | MessageBox.Show("No name specified", "Zip file name error")
31 | Return
32 | End If
33 |
34 | Dim astrFileNames() As String = Directory.GetFiles(sourceDir)
35 | Dim strmZipOutputStream As ZipOutputStream
36 |
37 | strmZipOutputStream = New ZipOutputStream(File.Create(targetName))
38 |
39 | Try
40 |
41 | REM Compression Level: 0-9
42 | REM 0: no(Compression)
43 | REM 9: maximum compression
44 | strmZipOutputStream.SetLevel(5)
45 |
46 | Dim strFile As String
47 | Dim abyBuffer(4096) As Byte
48 |
49 | For Each strFile In astrFileNames
50 | Dim strmFile As FileStream = File.OpenRead(strFile)
51 | Try
52 |
53 | Dim objZipEntry As ZipEntry = New ZipEntry(strFile)
54 |
55 | objZipEntry.DateTime = DateTime.Now
56 | objZipEntry.Size = strmFile.Length
57 |
58 | strmZipOutputStream.PutNextEntry(objZipEntry)
59 | StreamUtils.Copy(strmFile, strmZipOutputStream, abyBuffer)
60 | Finally
61 | strmFile.Close()
62 | End Try
63 | Next
64 |
65 | strmZipOutputStream.Finish()
66 |
67 | Finally
68 | strmZipOutputStream.Close()
69 | End Try
70 |
71 | MessageBox.Show("Operation complete")
72 | End Sub
73 |
74 | Private Sub btnBrowseForFolder_Click(sender As Object, e As RoutedEventArgs) Handles btnBrowseForFolder.Click
75 | Dim FolderBrowserDialog As WpfFolderBrowserDialog
76 | FolderBrowserDialog = New WpfFolderBrowserDialog
77 | If FolderBrowserDialog.ShowDialog() = True Then
78 | tbSourceDir.Text = FolderBrowserDialog.FileName
79 | End If
80 | End Sub
81 | End Class
82 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug.yml:
--------------------------------------------------------------------------------
1 | name: 🐛 Bug report
2 | description: Create a report to help us improve
3 | labels: ["bug"]
4 |
5 | body:
6 | - type: textarea
7 | id: description
8 | attributes:
9 | label: Describe the bug
10 | description: A clear and concise description of what the bug is
11 | validations:
12 | required: true
13 |
14 | - type: input
15 | id: reproduce-code
16 | attributes:
17 | description: |
18 | If possible, the best way to display an issue is by making a reproducable code snippet available at jsfiddle.
19 | Create a dotnet fiddle which reproduces your issue. You can use [this template](https://p1k.se/sharpziplib-repro) or [create a new one](https://dotnetfiddle.net/).
20 | placeholder: https://dotnetfiddle.net/r39r0c0d3
21 | label: Reproduction Code
22 |
23 | - type: textarea
24 | id: reproduce-steps
25 | attributes:
26 | label: Steps to reproduce
27 | description: Steps to reproduce the behavior
28 | placeholder: |
29 | 1. Go to '...'
30 | 2. Click on '....'
31 | 3. Scroll down to '....'
32 | 4. See error
33 | validations:
34 | required: true
35 |
36 | - id: expected
37 | type: textarea
38 | attributes:
39 | label: Expected behavior
40 | description: A clear and concise description of what you expected to happen.
41 | validations:
42 | required: true
43 |
44 | - id: operating-system
45 | type: dropdown
46 | attributes:
47 | label: Operating System
48 | multiple: true
49 | options:
50 | - Windows
51 | - macOS
52 | - Linux
53 | validations:
54 | required: false
55 |
56 | - id: framework
57 | type: dropdown
58 | attributes:
59 | label: Framework Version
60 | multiple: true
61 | options:
62 | - .NET 7
63 | - .NET 6
64 | - .NET 5
65 | - .NET Core v3 and earlier
66 | - .NET Framework 4.x
67 | - Unity
68 | - Other
69 | validations:
70 | required: false
71 |
72 | - id: tags
73 | type: dropdown
74 | attributes:
75 | label: Tags
76 | description: What areas are your issue related to?
77 | multiple: true
78 | options:
79 | - ZIP
80 | - GZip
81 | - Tar
82 | - BZip2
83 | - Encoding
84 | - Encryption
85 | - Documentation
86 | - Async
87 | - Performance
88 |
89 | - type: textarea
90 | attributes:
91 | label: Additional context
92 | description: Add any other context about the problem here.
93 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/cs/SampleAssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 |
4 | //
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | //
9 | [assembly: AssemblyTitle("ZF")]
10 | [assembly: AssemblyDescription("ZF A SharpZipLib Sample")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyProduct("")]
14 | [assembly: AssemblyCopyright("Copyright © 2000-2016 AlphaSierraPapa for the SharpZipLib Team")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 |
18 | //
19 | // Version information for an assembly consists of the following four values:
20 | //
21 | // Major Version
22 | // Minor Version
23 | // Build Number
24 | // Revision
25 | //
26 | // You can specify all the values or you can default the Revision and Build Numbers
27 | // by using the '*' as shown below:
28 |
29 | [assembly: AssemblyVersion("0.85.4.369")]
30 |
31 | //
32 | // In order to sign your assembly you must specify a key to use. Refer to the
33 | // Microsoft .NET Framework documentation for more information on assembly signing.
34 | //
35 | // Use the attributes below to control which key is used for signing.
36 | //
37 | // Notes:
38 | // (*) If no key is specified, the assembly is not signed.
39 | // (*) KeyName refers to a key that has been installed in the Crypto Service
40 | // Provider (CSP) on your machine. KeyFile refers to a file which contains
41 | // a key.
42 | // (*) If the KeyFile and the KeyName values are both specified, the
43 | // following processing occurs:
44 | // (1) If the KeyName can be found in the CSP, that key is used.
45 | // (2) If the KeyName does not exist and the KeyFile does exist, the key
46 | // in the KeyFile is installed into the CSP and used.
47 | // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
48 | // When specifying the KeyFile, the location of the KeyFile should be
49 | // relative to the project output directory which is
50 | // %Project Directory%\obj\. For example, if your KeyFile is
51 | // located in the project directory, you would specify the AssemblyKeyFile
52 | // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
53 | // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
54 | // documentation for more information on this.
55 | //
56 | [assembly: AssemblyDelaySign(false)]
57 | [assembly: AssemblyKeyFile("")]
58 | [assembly: AssemblyKeyName("")]
59 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/cs/sz/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/cs/zf/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0;netstandard2.1;net6.0
5 | true
6 | true
7 | true
8 | ../../assets/ICSharpCode.SharpZipLib.snk
9 | true
10 | true
11 | $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
12 |
13 |
14 |
15 |
16 | 1.4.2
17 | $(Version).13
18 | $(FileVersion)
19 | SharpZipLib
20 | ICSharpCode
21 | ICSharpCode
22 | SharpZipLib (#ziplib, formerly NZipLib) is a compression library for Zip, GZip, BZip2, and Tar written entirely in C# for .NET. It is implemented as an assembly (installable in the GAC), and thus can easily be incorporated into other projects (in any .NET language)
23 | MIT
24 | http://icsharpcode.github.io/SharpZipLib/
25 | images/sharpziplib-nuget-256x256.png
26 | https://github.com/icsharpcode/SharpZipLib
27 | Copyright © 2000-2022 SharpZipLib Contributors
28 | Compression Library Zip GZip BZip2 LZW Tar
29 | en-US
30 |
31 | Please see https://github.com/icsharpcode/SharpZipLib/wiki/Release-1.4.2 for more information.
32 | https://github.com/icsharpcode/SharpZipLib
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | True
47 | images
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/cs/Cmd_Tar/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/cs/FastZip/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | #
7 | # ******** NOTE ********
8 | # We have attempted to detect the languages in your repository. Please check
9 | # the `language` matrix defined below to confirm you have the correct set of
10 | # supported CodeQL languages.
11 | #
12 | name: "CodeQL"
13 |
14 | on:
15 | push:
16 | branches: [ master ]
17 | pull_request:
18 | # The branches below must be a subset of the branches above
19 | branches: [ master ]
20 | schedule:
21 | - cron: '40 7 * * 4'
22 |
23 | jobs:
24 | analyze:
25 | name: Analyze
26 | runs-on: ubuntu-latest
27 | permissions:
28 | actions: read
29 | contents: read
30 | security-events: write
31 |
32 | strategy:
33 | fail-fast: false
34 | matrix:
35 | language: [ 'csharp' ]
36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
37 | # Learn more:
38 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
39 |
40 | steps:
41 | - name: Checkout repository
42 | uses: actions/checkout@v3
43 |
44 | # Initializes the CodeQL tools for scanning.
45 | - name: Initialize CodeQL
46 | uses: github/codeql-action/init@v2
47 | with:
48 | languages: ${{ matrix.language }}
49 | # If you wish to specify custom queries, you can do so here or in a config file.
50 | # By default, queries listed here will override any specified in a config file.
51 | # Prefix the list here with "+" to use these queries and those in the config file.
52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main
53 |
54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55 | # If this step fails, then you should remove it and run the build manually (see below)
56 | - name: Autobuild
57 | uses: github/codeql-action/autobuild@v2
58 |
59 | # ℹ️ Command-line programs to run using the OS shell.
60 | # 📚 https://git.io/JvXDl
61 |
62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
63 | # and modify them (or add more) to build your code if your project
64 | # uses a compiled language
65 |
66 | #- run: |
67 | # make bootstrap
68 | # make release
69 |
70 | - name: Perform CodeQL Analysis
71 | uses: github/codeql-action/analyze@v2
72 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/cs/Cmd_Checksum/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/cs/Cmd_GZip/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/cs/Cmd_ZipInfo/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/ICSharpCode.SharpZipLib.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.28705.295
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Configuration", "Solution Configuration", "{F1097E98-4DEB-4A0A-81EE-5CEC667EBDF0}"
7 | ProjectSection(SolutionItems) = preProject
8 | .editorconfig = .editorconfig
9 | .gitattributes = .gitattributes
10 | .gitignore = .gitignore
11 | Rebracer.xml = Rebracer.xml
12 | EndProjectSection
13 | EndProject
14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.SharpZipLib", "src\ICSharpCode.SharpZipLib\ICSharpCode.SharpZipLib.csproj", "{C53BEB8A-0989-43A7-B3EC-F7028749FA71}"
15 | EndProject
16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.SharpZipLib.Tests", "test\ICSharpCode.SharpZipLib.Tests\ICSharpCode.SharpZipLib.Tests.csproj", "{82211166-9C45-4603-8E3A-2CA2EFFCBC26}"
17 | EndProject
18 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.SharpZipLib.Benchmark", "benchmark\ICSharpCode.SharpZipLib.Benchmark\ICSharpCode.SharpZipLib.Benchmark.csproj", "{C51E638B-DDD0-48B6-A6BD-EBC4E6A104C7}"
19 | EndProject
20 | Global
21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
22 | Debug|Any CPU = Debug|Any CPU
23 | Release|Any CPU = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
26 | {C53BEB8A-0989-43A7-B3EC-F7028749FA71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {C53BEB8A-0989-43A7-B3EC-F7028749FA71}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {C53BEB8A-0989-43A7-B3EC-F7028749FA71}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {C53BEB8A-0989-43A7-B3EC-F7028749FA71}.Release|Any CPU.Build.0 = Release|Any CPU
30 | {82211166-9C45-4603-8E3A-2CA2EFFCBC26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31 | {82211166-9C45-4603-8E3A-2CA2EFFCBC26}.Debug|Any CPU.Build.0 = Debug|Any CPU
32 | {82211166-9C45-4603-8E3A-2CA2EFFCBC26}.Release|Any CPU.ActiveCfg = Release|Any CPU
33 | {82211166-9C45-4603-8E3A-2CA2EFFCBC26}.Release|Any CPU.Build.0 = Release|Any CPU
34 | {C51E638B-DDD0-48B6-A6BD-EBC4E6A104C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35 | {C51E638B-DDD0-48B6-A6BD-EBC4E6A104C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
36 | {C51E638B-DDD0-48B6-A6BD-EBC4E6A104C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
37 | {C51E638B-DDD0-48B6-A6BD-EBC4E6A104C7}.Release|Any CPU.Build.0 = Release|Any CPU
38 | EndGlobalSection
39 | GlobalSection(SolutionProperties) = preSolution
40 | HideSolutionNode = FALSE
41 | EndGlobalSection
42 | GlobalSection(ExtensibilityGlobals) = postSolution
43 | SolutionGuid = {0A049193-65F8-49AF-82CB-75D42563DA16}
44 | EndGlobalSection
45 | EndGlobal
46 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/cs/Cmd_BZip2/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/cs/unzipfile/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/vb/WpfCreateZipFile/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/samples/ICSharpCode.SharpZipLib.Samples/cs/CreateZipFile/CreateZipFile.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using ICSharpCode.SharpZipLib.Zip;
4 |
5 | class CreateZipFile
6 | {
7 | public static void Main(string[] args)
8 | {
9 | // Perform some simple parameter checking. More could be done
10 | // like checking the target file name is ok, disk space, and lots
11 | // of other things, but for a demo this covers some obvious traps.
12 | if (args.Length < 2) {
13 | Console.WriteLine("Usage: CreateZipFile Path ZipFile");
14 | return;
15 | }
16 |
17 | if (!Directory.Exists(args[0])) {
18 | Console.WriteLine("Cannot find directory '{0}'", args[0]);
19 | return;
20 | }
21 |
22 | try {
23 | // Depending on the directory this could be very large and would require more attention
24 | // in a commercial package.
25 | string[] filenames = Directory.GetFiles(args[0]);
26 |
27 | // 'using' statements guarantee the stream is closed properly which is a big source
28 | // of problems otherwise. Its exception safe as well which is great.
29 | using (ZipOutputStream s = new ZipOutputStream(File.Create(args[1])))
30 | {
31 |
32 | s.SetLevel(9); // 0 - store only to 9 - means best compression
33 |
34 | byte[] buffer = new byte[4096];
35 |
36 | foreach (string file in filenames)
37 | {
38 |
39 | // Using GetFileName makes the result compatible with XP
40 | // as the resulting path is not absolute.
41 | var entry = new ZipEntry(Path.GetFileName(file));
42 |
43 | // Setup the entry data as required.
44 |
45 | // Crc and size are handled by the library for seakable streams
46 | // so no need to do them here.
47 |
48 | // Could also use the last write time or similar for the file.
49 | entry.DateTime = DateTime.Now;
50 | s.PutNextEntry(entry);
51 |
52 | using (FileStream fs = File.OpenRead(file)) {
53 |
54 | // Using a fixed size buffer here makes no noticeable difference for output
55 | // but keeps a lid on memory usage.
56 | int sourceBytes;
57 | do
58 | {
59 | sourceBytes = fs.Read(buffer, 0, buffer.Length);
60 | s.Write(buffer, 0, sourceBytes);
61 | } while (sourceBytes > 0);
62 | }
63 | }
64 |
65 | // Finish/Close arent needed strictly as the using statement does this automatically
66 |
67 | // Finish is important to ensure trailing information for a Zip file is appended. Without this
68 | // the created file would be invalid.
69 | s.Finish();
70 |
71 | // Close is important to wrap things up and unlock the file.
72 | s.Close();
73 | }
74 | } catch (Exception ex) {
75 | Console.WriteLine("Exception during processing {0}", ex);
76 |
77 | // No need to rethrow the exception as for our purposes its handled.
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/test/ICSharpCode.SharpZipLib.Tests/Lzw/LzwTests.cs:
--------------------------------------------------------------------------------
1 | using ICSharpCode.SharpZipLib.Lzw;
2 | using ICSharpCode.SharpZipLib.Tests.TestSupport;
3 | using NUnit.Framework;
4 | using System.IO;
5 |
6 | namespace ICSharpCode.SharpZipLib.Tests.Lzw
7 | {
8 | [TestFixture]
9 | public class LzwTestSuite
10 | {
11 | //[Test]
12 | //[Category("LZW")]
13 | //public void TestLzw() {
14 | // LzwInputStream str = new LzwInputStream(File.OpenRead("D:\\hour2890.09n.Z"));
15 | // Stream raw = File.OpenRead("D:\\hour2890.09n");
16 | // byte[] data = new byte[1028 * 1028];
17 | // byte[] dataRaw = new byte[1028 * 1028];
18 | // raw.Read(dataRaw, 0, 1028);
19 | // str.Read(data, 0, 1028);
20 | // for (int i = 0; i < 1028; i++) {
21 | // Assert.AreEqual(data[i], dataRaw[i]);
22 | // }
23 |
24 | // Stream output = File.Open("D:\\erase.txt", FileMode.CreateNew);
25 | // output.Write(data, 0, 1028);
26 | // output.Close();
27 | // raw.Close();
28 | //}
29 |
30 | //[Test]
31 | //[Category("LZW")]
32 | //public void TestStream() {
33 | // using (Stream inStream = new LzwInputStream(File.OpenRead("D:\\hour2890.09n.Z")))
34 | // using (FileStream outStream = File.Create("D:\\hour2890.09n")) {
35 | // byte[] buffer = new byte[4096];
36 | // StreamUtils.Copy(inStream, outStream, buffer);
37 | // }
38 | //}
39 |
40 | [Test]
41 | [Category("LZW")]
42 | public void ZeroLengthInputStream()
43 | {
44 | var lis = new LzwInputStream(new MemoryStream());
45 | bool exception = false;
46 | try
47 | {
48 | lis.ReadByte();
49 | }
50 | catch
51 | {
52 | exception = true;
53 | }
54 |
55 | Assert.IsTrue(exception, "reading from an empty stream should cause an exception");
56 | }
57 |
58 | [Test]
59 | [Category("LZW")]
60 | public void InputStreamOwnership()
61 | {
62 | var memStream = new TrackedMemoryStream();
63 | var s = new LzwInputStream(memStream);
64 |
65 | Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
66 | Assert.IsFalse(memStream.IsDisposed, "Shouldnt be disposed initially");
67 |
68 | s.Close();
69 |
70 | Assert.IsTrue(memStream.IsClosed, "Should be closed after parent owner close");
71 | Assert.IsTrue(memStream.IsDisposed, "Should be disposed after parent owner close");
72 |
73 | memStream = new TrackedMemoryStream();
74 | s = new LzwInputStream(memStream);
75 |
76 | Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
77 | Assert.IsFalse(memStream.IsDisposed, "Shouldnt be disposed initially");
78 |
79 | s.IsStreamOwner = false;
80 | s.Close();
81 |
82 | Assert.IsFalse(memStream.IsClosed, "Should not be closed after parent owner close");
83 | Assert.IsFalse(memStream.IsDisposed, "Should not be disposed after parent owner close");
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/BZip2/BZip2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace ICSharpCode.SharpZipLib.BZip2
5 | {
6 | ///
7 | /// An example class to demonstrate compression and decompression of BZip2 streams.
8 | ///
9 | public static class BZip2
10 | {
11 | ///
12 | /// Decompress the input writing
13 | /// uncompressed data to the output stream
14 | ///
15 | /// The readable stream containing data to decompress.
16 | /// The output stream to receive the decompressed data.
17 | /// Both streams are closed on completion if true.
18 | public static void Decompress(Stream inStream, Stream outStream, bool isStreamOwner)
19 | {
20 | if (inStream == null)
21 | throw new ArgumentNullException(nameof(inStream));
22 |
23 | if (outStream == null)
24 | throw new ArgumentNullException(nameof(outStream));
25 |
26 | try
27 | {
28 | using (BZip2InputStream bzipInput = new BZip2InputStream(inStream))
29 | {
30 | bzipInput.IsStreamOwner = isStreamOwner;
31 | Core.StreamUtils.Copy(bzipInput, outStream, new byte[4096]);
32 | }
33 | }
34 | finally
35 | {
36 | if (isStreamOwner)
37 | {
38 | // inStream is closed by the BZip2InputStream if stream owner
39 | outStream.Dispose();
40 | }
41 | }
42 | }
43 |
44 | ///
45 | /// Compress the input stream sending
46 | /// result data to output stream
47 | ///
48 | /// The readable stream to compress.
49 | /// The output stream to receive the compressed data.
50 | /// Both streams are closed on completion if true.
51 | /// Block size acts as compression level (1 to 9) with 1 giving
52 | /// the lowest compression and 9 the highest.
53 | public static void Compress(Stream inStream, Stream outStream, bool isStreamOwner, int level)
54 | {
55 | if (inStream == null)
56 | throw new ArgumentNullException(nameof(inStream));
57 |
58 | if (outStream == null)
59 | throw new ArgumentNullException(nameof(outStream));
60 |
61 | try
62 | {
63 | using (BZip2OutputStream bzipOutput = new BZip2OutputStream(outStream, level))
64 | {
65 | bzipOutput.IsStreamOwner = isStreamOwner;
66 | Core.StreamUtils.Copy(inStream, bzipOutput, new byte[4096]);
67 | }
68 | }
69 | finally
70 | {
71 | if (isStreamOwner)
72 | {
73 | // outStream is closed by the BZip2OutputStream if stream owner
74 | inStream.Dispose();
75 | }
76 | }
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/ICSharpCode.SharpZipLib/Core/Exceptions/ValueOutOfRangeException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.Serialization;
3 |
4 | namespace ICSharpCode.SharpZipLib
5 | {
6 | ///
7 | /// Indicates that a value was outside of the expected range when decoding an input stream
8 | ///
9 | [Serializable]
10 | public class ValueOutOfRangeException : StreamDecodingException
11 | {
12 | ///
13 | /// Initializes a new instance of the ValueOutOfRangeException class naming the causing variable
14 | ///
15 | /// Name of the variable, use: nameof()
16 | public ValueOutOfRangeException(string nameOfValue)
17 | : base($"{nameOfValue} out of range") { }
18 |
19 | ///
20 | /// Initializes a new instance of the ValueOutOfRangeException class naming the causing variable,
21 | /// it's current value and expected range.
22 | ///
23 | /// Name of the variable, use: nameof()
24 | /// The invalid value
25 | /// Expected maximum value
26 | /// Expected minimum value
27 | public ValueOutOfRangeException(string nameOfValue, long value, long maxValue, long minValue = 0)
28 | : this(nameOfValue, value.ToString(), maxValue.ToString(), minValue.ToString()) { }
29 |
30 | ///
31 | /// Initializes a new instance of the ValueOutOfRangeException class naming the causing variable,
32 | /// it's current value and expected range.
33 | ///
34 | /// Name of the variable, use: nameof()
35 | /// The invalid value
36 | /// Expected maximum value
37 | /// Expected minimum value
38 | public ValueOutOfRangeException(string nameOfValue, string value, string maxValue, string minValue = "0") :
39 | base($"{nameOfValue} out of range: {value}, should be {minValue}..{maxValue}")
40 | { }
41 |
42 | private ValueOutOfRangeException()
43 | {
44 | }
45 |
46 | private ValueOutOfRangeException(string message, Exception innerException) : base(message, innerException)
47 | {
48 | }
49 |
50 | ///
51 | /// Initializes a new instance of the ValueOutOfRangeException class with serialized data.
52 | ///
53 | ///
54 | /// The System.Runtime.Serialization.SerializationInfo that holds the serialized
55 | /// object data about the exception being thrown.
56 | ///
57 | ///
58 | /// The System.Runtime.Serialization.StreamingContext that contains contextual information
59 | /// about the source or destination.
60 | ///
61 | protected ValueOutOfRangeException(SerializationInfo info, StreamingContext context)
62 | : base(info, context)
63 | {
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
65 | # Force bash scripts to always use lf line endings so that if a repo is accessed
66 | # in Unix via a file share from Windows, the scripts will work.
67 | *.sh text eol=lf
68 |
--------------------------------------------------------------------------------
/appveyor.yml.old:
--------------------------------------------------------------------------------
1 | version: 1.0.{build}
2 | branches:
3 | only:
4 | - master
5 | except:
6 | - gh-pages
7 | - coverity_scan
8 |
9 | skip_tags: true
10 | image: Visual Studio 2017
11 |
12 | init:
13 | - git config --global core.autocrlf input
14 |
15 | cache:
16 | - packages -> **\packages.config
17 |
18 | assembly_info:
19 | patch: true
20 | file: 'src\**\AssemblyInfo.cs'
21 | assembly_version: '{version}'
22 | assembly_file_version: '{version}'
23 | assembly_informational_version: '{version}'
24 |
25 | nuget:
26 | account_feed: true
27 | project_feed: true
28 | disable_publish_on_pr: true
29 |
30 | configuration: Release
31 |
32 | environment:
33 | COVERALLS_REPO_TOKEN:
34 | secure: B/NQfoRYUnKLGS5KJSJrGBvcYD0Jv+coudjJMY2jf+gqvqDWral9CDmv2i0WovY7
35 | COVERITY_TOKEN:
36 | secure: n9NA/kasTqxUc8UBfQ2cBlZcDyFJvko1gcMzVTDvZq8=
37 | COVERITY_EMAIL:
38 | secure: j/N0ZmnUZYKnS2nGocKyNsXoKQBfWTBOg+VI4q7yMn4=
39 |
40 | before_build:
41 | - dotnet restore ICSharpCode.SharpZipLib.sln
42 |
43 | build_script:
44 | - ps: Build\run-appveyor-build.ps1
45 |
46 | test_script:
47 | - dotnet test test\ICSharpCode.SharpZipLib.Tests
48 |
49 | after_test:
50 | - cmd: Build\run-opencover.cmd
51 | - cmd: packages\coveralls.io.1.3.4\tools\coveralls.net.exe --opencover Documentation\opencover-results-release.xml
52 | - cmd: nuget pack Build\ICSharpCode.SharpZipLib.nuspec -BasePath bin\Release\ -OutputDirectory bin\Release\ -Version %APPVEYOR_BUILD_VERSION%
53 |
54 | test_script:
55 | - cmd: nunit3-console --framework=net-4.5 --labels=All --testlist=ICSharpCode.SharpZipLib.Tests\PassingTests.txt --result=Documentation\nunit3-test-results-appveyor.xml;format=AppVeyor bin\Release\ICSharpCode.SharpZipLib.Tests.dll
56 |
57 | artifacts:
58 | - path: bin\Release
59 | name: BuildRelease
60 | - path: bin\**\*.nupkg
61 | name: NuGet
62 | - path: Documentation\*.xml
63 | name: TestResults
64 | - path: Documentation\coverity.zip
65 | name: Coverity
66 |
67 | deploy:
68 | - provider: GitHub
69 | release: sharpziplib-dogfood-{version}
70 | description: 'Something To Eat'
71 | auth_token:
72 | secure: pZ5zHJ/2mZsmqQH0gPke0LMqSgUhz79wbcCjdDTCEIl6hRJYlYhkaPianw2hz26k # your encrypted token from GitHub
73 | artifact: BuildRelease
74 | draft: true
75 | prerelease: true
76 | on:
77 | branch: master
78 | # appveyor_repo_tag: true # deploy on tag push only
79 | - provider: NuGet
80 | skip_symbols: false
81 | symbol_server: https://ci.appveyor.com/nuget/mcneight-93sw9hg8ve02/api/v2/package
82 | api_key:
83 | secure: z+iy8Iv5qqQghGrATRbx2I921HCHD7x7/xIrmkGGauMgpA/d1DBoOVUNNCHLE9Dj
84 | artifact: NuGet
85 |
86 | notifications:
87 | - provider: Email
88 | to:
89 | - mcneight+appveyor@gmail.com
90 | subject: Build {{status}}
91 | message: Version {{version}} {{commitId}} from {{branch}} {{status}} {{message}}
92 | on_build_success: true
93 | on_build_failure: true
94 | on_build_status_changed: true
--------------------------------------------------------------------------------
/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipCorruptionHandling.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Threading;
4 | using ICSharpCode.SharpZipLib.Zip;
5 | using NUnit.Framework;
6 |
7 | namespace ICSharpCode.SharpZipLib.Tests.Zip
8 | {
9 | public class ZipCorruptionHandling
10 | {
11 |
12 | const string TestFileZeroCodeLength = "UEsDBBQA+AAIANwyZ0U5T8HwjQAAAL8AAAAIABUAbGltZXJpY2t" +
13 | "VVAkAAzBXXFR6LmBUVXgEAPQB9AEFjTEOwjAQBHu/YkVDg3gHoUaivjgHtmKfI5+D5d9zbndHM6/AldFJQTIJ" +
14 | "PrVkPOkgce9QlJFi5hr9rhD+cUUvZ9qgnuRuBAtId97Qw0AL1Kbw5h6MykeKdlyWdlWs7OlUdgsodRqKVo0v8" +
15 | "JWyGWZ6mLpuiii2t2Bl0mZ54QksOIpqXNPATF/eH1BLAQIXAxQAAgAIANxQZ0U5T8HwjQAAAL8AAAAIAA0AAA" +
16 | "AAAAEAAACggQAAAABsaW1lcgEAQwAAAMgAAAAAAA==";
17 |
18 | [Test]
19 | [Category("Zip")]
20 | public void ZeroCodeLengthZipFile()
21 | {
22 | Assert.Throws(() => {
23 | Exception threadException = null;
24 | var testThread = new Thread(() => {
25 | try {
26 | var fileBytes = Convert.FromBase64String(TestFileZeroCodeLength);
27 | using (var ms = new MemoryStream(fileBytes))
28 | using (var zip = new ZipInputStream(ms))
29 | {
30 | while (zip.GetNextEntry() != null) { }
31 | }
32 | }
33 | catch (Exception x) {
34 | threadException = x;
35 | }
36 | });
37 |
38 | testThread.Start();
39 |
40 | if(!testThread.Join(5000)){
41 | // Aborting threads is deprecated in .NET Core, but if we don't do this,
42 | // the poor CI will hang for 2 hours upon running this test
43 | ThreadEx.Abort(testThread);
44 | throw new TimeoutException("Timed out waiting for GetNextEntry() to return");
45 | }
46 | else if(threadException != null){
47 | throw threadException;
48 | }
49 | });
50 | }
51 |
52 | const string TestFileBadCDGoodCD64 = @"UEsDBC0AAAAIANhy+k4cj+r8//////////8IABQAdGVzdGZpbGUBABAAAAA
53 | AAAAAAAAUAAAAAAAAACtJLS5Jy8xJVUjOzytJzSsp5gIAUEsBAjMALQAAAAgA2HL6ThyP6vz//////////wgAFAAAAAAAA
54 | AAAAAAAAAAAAHRlc3RmaWxlAQAQABIAAAAAAAAAFAAAAAAAAABQSwUGAAAAAAEAAQBKAAAATgAAAAAA";
55 |
56 | [Test]
57 | [Category("Zip")]
58 | public void CorruptCentralDirWithCorrectZip64CD()
59 | {
60 | var fileBytes = Convert.FromBase64String(TestFileBadCDGoodCD64);
61 | using (var ms = new MemoryStream(fileBytes))
62 | using (var zip = new ZipFile(ms))
63 | {
64 | Assert.AreEqual(1, zip.Count);
65 | Assert.AreNotEqual(0, zip[0].Size, "Uncompressed file size read from corrupt CentralDir instead of CD64");
66 | }
67 | }
68 |
69 | }
70 |
71 | }
--------------------------------------------------------------------------------