Skip to content
Merged
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 30 additions & 3 deletions website/cue/reference/remap/functions/decode_lz4.cue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package metadata
remap: functions: decode_lz4: {
category: "Codec"
description: """
Decodes the `value` (an lz4 string) into its original string.
Decodes the `value` (an lz4 string) into its original string. `buf_size` is the size of the buffer to decode into, this must be equal to or larger than the uncompressed size.
If `prepended_size` is set to `true`, it expects the original uncompressed size to be prepended to the compressed data.
`prepended_size` is useful for some implementations of lz4 that require the original size to be known before decoding.
"""

arguments: [
Expand All @@ -13,17 +15,42 @@ remap: functions: decode_lz4: {
required: true
type: ["string"]
},
{
name: "buf_size"
description: "The size of the buffer to decode into, this must be equal to or larger than the uncompressed size."
required: false
default: 1024 * 1024 // 1 MiB
type: ["integer"]
},
{
name: "prepended_size"
description: "Some implementations of lz4 require the original uncompressed size to be prepended to the compressed data."
required: false
default: false
type: ["boolean"]
},
]
internal_failure_reasons: [
"`value` unable to decode value with lz4 decoder.",
"`value` unable to decode value with lz4 frame decoder.",
"`value` unable to decode value with lz4 block decoder.",
"`value` unable to decode because the output is too large for the buffer.",
"`value` unable to decode because the prepended size is not a valid integer.",
]
return: types: ["string"]

examples: [
{
title: "Decode Lz4 data"
title: "Decode Lz4 data with prepended size."
source: #"""
encoded_text = decode_base64!("LAAAAPAdVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIDEzIGxhenkgZG9ncy4=")
decode_lz4!(encoded_text, use_prepended_size: true)
"""#
return: "The quick brown fox jumps over 13 lazy dogs."
},
{
title: "Decode Lz4 data without prepended size."
source: #"""
encoded_text = decode_base64!("8B1UaGUgcXVpY2sgYnJvd24gZm94IGp1bXBzIG92ZXIgMTMgbGF6eSBkb2dzLg==")
decode_lz4!(encoded_text)
"""#
return: "The quick brown fox jumps over 13 lazy dogs."
Expand Down
11 changes: 10 additions & 1 deletion website/cue/reference/remap/functions/encode_lz4.cue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package metadata
remap: functions: encode_lz4: {
category: "Codec"
description: """
Encodes the `value` to [Lz4](\(urls.lz4)).
Encodes the `value` to [Lz4](\(urls.lz4)). This function compresses the input string into an lz4 block.
If `prepend_size` is set to `true`, it prepends the original uncompressed size to the compressed data.
This is useful for some implementations of lz4 that require the original size to be known before decoding.
"""

arguments: [
Expand All @@ -13,6 +15,13 @@ remap: functions: encode_lz4: {
required: true
type: ["string"]
},
{
name: "prepend_size"
description: "Whether to prepend the original size to the compressed data."
required: false
default: false
type: ["boolean"]
},
]
internal_failure_reasons: []
return: types: ["string"]
Expand Down
Loading