-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1a4c57
commit c50df21
Showing
4 changed files
with
41 additions
and
15 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
interface BrotliDecoderResult { | ||
|
||
namespace BrotliEncoderMode { | ||
readonly attribute int BROTLI_MODE_GENERIC; | ||
/** Compression mode for UTF-8 formatted text input. */ | ||
readonly attribute int BROTLI_MODE_TEXT; | ||
/** Compression mode used in WOFF 2.0. */ | ||
readonly attribute int BROTLI_MODE_FONT; | ||
}; | ||
|
||
namespace global { | ||
int BrotliDecoderDecompress ([ArrayLength="encoded_buffer"] any encoded_size, [Const,Array] octet encoded_buffer, [Array,Size,ConvertInputArray] any decoded_size, [Array,ConvertInputArray] octet decoded_buffer); | ||
boolean BrotliEncoderCompress (int quality, int lgwin, BrotliEncoderMode mode, [ArrayLength="input_buffer"] any input_size, [Const,Array] octet input_buffer, [Array,Size,ConvertInputArray] any encoded_size, [Array,ConvertInputArray] octet encoded_buffer); | ||
int BrotliDecoderDecompress ([ArrayLength="encoded_buffer"] any encoded_size, [Const,Array] octet encoded_buffer, [ArrayLengthRef="decoded_buffer"] any decoded_size, [Array,ConvertInputArray] octet decoded_buffer); | ||
boolean BrotliEncoderCompress (int quality, int lgwin, [Enum="BrotliEncoderMode"] any mode, [ArrayLength="input_buffer"] any input_size, [Const,Array] octet input_buffer, [ArrayLengthRef="encoded_buffer"] any encoded_size, [Array,ConvertInputArray] octet encoded_buffer); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
local module = dofile("bin/brotli.lua") | ||
local module = dofile("bin/brotli.pure.lua") | ||
|
||
module.init() | ||
|
||
local function strToArr(str) | ||
return {str:byte(1,-1)} | ||
local out = {} for i=1,#str do out[i] = str:byte(i,i) end return out | ||
end | ||
|
||
local compLen,compBuf = {2000},{} | ||
for i=1,2000 do compBuf[i] = 0 end | ||
assert(module.bindings.global.BrotliEncoderCompress(1,22,0,strToArr("Hello World"),compLen,compBuf) == 1) | ||
local inputStr = ("Hello World"):rep(10000) | ||
|
||
local fixed = {} | ||
for i=1,compLen[1] do fixed[i] = compBuf[i] end | ||
local compBuf = {__wasmMaxLen = #inputStr * 2} | ||
local t = os.clock() | ||
assert(module.bindings.global.BrotliEncoderCompress( | ||
5, | ||
22, | ||
module.bindings.BrotliEncoderMode.BROTLI_MODE_GENERIC, | ||
strToArr(inputStr), | ||
compBuf | ||
),"Compression failed") | ||
print("Compression took "..(os.clock() - t).."s") | ||
|
||
local outLen,outBuf = {2000},{} | ||
assert(module.bindings.global.BrotliDecoderDecompress(fixed,outLen,outBuf) == 1) | ||
t = os.clock() | ||
local outBuf = {__wasmMaxLen = #inputStr} | ||
assert(module.bindings.global.BrotliDecoderDecompress(compBuf,outBuf,"Decompression failed")) | ||
print("Decompression took "..(os.clock() - t).."s") | ||
|
||
for i=1,outLen[1] do io.write(string.char(outBuf[i])) end | ||
-- for i=1,outBuf.len() do io.write(string.char(outBuf[i])) end |
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