瀏覽代碼

Merge pull request #1 from ClarkThan/fix-returned-iolist-when-encode

fix: sometimes encode return iolist unexpectedly
pull/149/head
Andrew Dryga 5 年之前
committed by GitHub
父節點
當前提交
8c6f0c1b88
沒有發現已知的金鑰在資料庫的簽署中 GPG 金鑰 ID: 4AEE18F83AFDEB23
共有 2 個檔案被更改,包括 8 行新增4 行删除
  1. +5
    -3
      lib/jiffy.ex
  2. +3
    -1
      mix.lock

+ 5
- 3
lib/jiffy.ex 查看文件

@ -68,7 +68,9 @@ defmodule Jiffy do
"""
@spec encode!(any, opts :: :jiffy.encode_option()) :: {:ok, any()} | no_return()
def encode!(data, opts \\ []) do
:jiffy.encode(data, @encode_options ++ opts)
data
|> :jiffy.encode(@encode_options ++ opts)
|> :erlang.iolist_to_binary()
end
@doc """
@ -92,7 +94,7 @@ defmodule Jiffy do
iex> Jiffy.decode("[1,2,3]")
{:ok, [1, 2, 3]}
"""
@spec decode(String.t, opts :: :jiffy.decode_option()) :: {:ok, any()} | {:error, atom()}
@spec decode(String.t(), opts :: :jiffy.decode_option()) :: {:ok, any()} | {:error, atom()}
def decode(data, opts \\ []) do
{:ok, decode!(data, opts)}
catch
@ -109,7 +111,7 @@ defmodule Jiffy do
iex> Jiffy.decode!("[1,2,3]")
[1, 2, 3]
"""
@spec decode!(String.t, opts :: :jiffy.decode_option()) :: any() | no_return()
@spec decode!(String.t(), opts :: :jiffy.decode_option()) :: any() | no_return()
def decode!(data, opts \\ []) do
:jiffy.decode(data, @decode_options ++ opts)
end

+ 3
- 1
mix.lock 查看文件

@ -1 +1,3 @@
%{"elixir_make": {:hex, :elixir_make, "0.4.0", "992f38fabe705bb45821a728f20914c554b276838433349d4f2341f7a687cddf", [:mix], []}}
%{
"elixir_make": {:hex, :elixir_make, "0.4.0", "992f38fabe705bb45821a728f20914c554b276838433349d4f2341f7a687cddf", [:mix], [], "hexpm", "4549183795460c581fd82010d10862e46bcf796e2039d16c255bad3e408f435d"},
}

Loading…
取消
儲存