-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added support for op_compressed (zlib and zstd)
- Loading branch information
Showing
12 changed files
with
266 additions
and
58 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
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,45 @@ | ||
defmodule Mongo.Compressor do | ||
@moduledoc false | ||
|
||
@zlib_compressor_id 2 | ||
if Code.ensure_loaded?(:ezstd) do | ||
@zstd_compressor_id 3 | ||
end | ||
|
||
def compress(binary, :zlib) do | ||
{@zlib_compressor_id, :zlib.compress(binary)} | ||
end | ||
|
||
if Code.ensure_loaded?(:ezstd) do | ||
def compress(binary, :zstd) when is_binary(binary) do | ||
{@zstd_compressor_id, :ezstd.compress(binary)} | ||
end | ||
|
||
def compress(iodata, :zstd) when is_list(iodata) do | ||
{@zstd_compressor_id, | ||
iodata | ||
|> IO.iodata_to_binary() | ||
|> :ezstd.compress()} | ||
end | ||
end | ||
|
||
def uncompress(binary, @zlib_compressor_id) do | ||
:zlib.uncompress(binary) | ||
end | ||
|
||
if Code.ensure_loaded?(:ezstd) do | ||
def uncompress(binary, @zstd_compressor_id) do | ||
:ezstd.decompress(binary) | ||
end | ||
end | ||
|
||
def uncompress(binary, :zlib) do | ||
:zlib.uncompress(binary) | ||
end | ||
|
||
if Code.ensure_loaded?(:ezstd) do | ||
def uncompress(binary, :zstd) do | ||
:ezstd.decompress(binary) | ||
end | ||
end | ||
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.