Skip to content

Commit

Permalink
Push missing compression file
Browse files Browse the repository at this point in the history
  • Loading branch information
PixeLInc committed Aug 13, 2020
1 parent c05ed38 commit f36997f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions source/droid/gateway/compression.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module droid.gateway.compression;

import droid.exception;
import std.zlib,
std.stdio,
std.conv : to;

enum CompressionType : string {
NONE = "",
ZLIB = "zlib",
ZLIB_STREAM = "zlib-stream"
}
class Decompressor {
string read(ubyte[] data) {
throw new DroidException("Compression type not supported!");
}
}

class ZLibStream : Decompressor {
const ulong[] ZLIB_SUFFIX = [0x0, 0x0, 0xFF, 0xFF];
UnCompress decompressor;

this() {
decompressor = new UnCompress(HeaderFormat.deflate);
}

override string read(ubyte[] data) {
if (data[$-4..$] != ZLIB_SUFFIX) {
throw new DroidException("ZLib-Stream compression enabled but invalid data was recieved!");
}

string decompressed = to!string(decompressor.uncompress(data));
decompressor.flush();

return decompressed;
}
}

0 comments on commit f36997f

Please sign in to comment.