-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #726 from Erior/feature/7ZipDelta
Add support for 7ZipDelta decompress
- Loading branch information
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace SharpCompress.Compressors.Filters | ||
{ | ||
internal class DeltaFilter : Filter | ||
{ | ||
private const int DISTANCE_MIN = 1; | ||
private const int DISTANCE_MAX = 256; | ||
private const int DISTANCE_MASK = DISTANCE_MAX - 1; | ||
|
||
private int _distance; | ||
private byte[] _history; | ||
private int _position; | ||
|
||
public DeltaFilter(bool isEncoder, Stream baseStream, byte[] info) | ||
: base(isEncoder, baseStream, 1) | ||
{ | ||
_distance = info[0]; | ||
_history = new byte[DISTANCE_MAX]; | ||
_position = 0; | ||
|
||
if (_distance < DISTANCE_MIN) | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
} | ||
|
||
protected override int Transform(byte[] buffer, int offset, int count) | ||
{ | ||
int end = offset + count; | ||
|
||
for( int i = offset; i < end; i++ ) | ||
{ | ||
buffer[i] += _history[(_distance + _position--) & DISTANCE_MASK]; | ||
_history[_position & DISTANCE_MASK] = buffer[i]; | ||
} | ||
|
||
return count; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.