Roblox UtilitiesDevlHub Roblox Documentation

Class

EncodingService

NotCreatableServiceNotReplicated
Inherits
Instance › Object
Memory category
Instances

Service providing common encoding, hashing, and compression methods.

Service providing common encoding, hashing, and compression methods.

Methods 7#

Base64DecodeDecodes a Base64-encoded buffer into a new buffer containing the original binary data.Safe
Base64EncodeEncodes binary data from a buffer into Base64 format, returning the result as a new buffer.Safe
CompressBufferCompresses binary buffer data using the specified algorithm and compression level.Safe
ComputeBufferHashComputes a cryptographic hash of a buffer's binary data using the specified algorithm.Safe
ComputeStringHashComputes a cryptographic hash of a string using the specified algorithm.Safe
DecompressBufferDecompresses binary buffer data that was compressed with the specified algorithm.Safe
GetDecompressedBufferSizeReturns the expected decompressed size of a compressed buffer, or nil if the size is unknown or invalid.Safe

Base64Decode(input: buffer): buffer#

Safe

Method takes a buffer with data encoded in Base64 format and decodes it into a new buffer.

If the input is not valid Base64 data, this method throws an error.

Base64 data is most often used for binary data encoding, so these functions are designed to work on buffer values.

If the data is stored in a string, buffer.fromstring can be used to quickly convert it into a buffer.

NameTypeDefaultDescription
inputbufferbuffer containing Base64 data to decode
Returns
  • buffer — buffer with the decoded result

Base64Encode(input: buffer): buffer#

Safe

Method takes a buffer with binary data and encodes it using Base64.

Encoded result is returned as a new buffer.

NameTypeDefaultDescription
inputbufferbuffer containing binary data to encode
Returns
  • buffer — buffer with the encoded result

CompressBuffer(input: buffer, algorithm: CompressionAlgorithm, compressionLevel: int = 1): buffer#

Safe

Compresses the binary data stored in a buffer using the specified compression algorithm and compression level. The higher the compression level, the longer it takes to compress, but the resulting compression ratio might increase.

For CompressionAlgorithm.Zstd, the allowed compression values are from -7 to 22 inclusive.

NameTypeDefaultDescription
inputbufferbuffer with binary data to compress
algorithmCompressionAlgorithmCompressionAlgorithm to use for compression
compressionLevelint1optional integer compression level to use
Returns
  • buffer — buffer with compressed binary data

ComputeBufferHash(input: buffer, algorithm: HashAlgorithm): buffer#

Safe

Uses a cryptographic hash function to compute a hash of the input buffer. Returns a new buffer with the binary data.

See descriptions of HashAlgorithm to learn of the supported digest size for each hash.

Do not use this for passwords#

None of these hashes are password hashing algorithms. They were designed to be fast to execute, whereas password hashing should never be fast. You shouldn't use this function for computing password hashes that will be stored, or for deriving keys from passwords.

NameTypeDefaultDescription
inputbufferbuffer with binary data to compute hash for
algorithmHashAlgorithmHashAlgorithm cryptographic hash function
Returns
  • buffer — buffer with the binary data of the hash

ComputeStringHash(input: string, algorithm: HashAlgorithm): string#

Safe

Uses a cryptographic hash function to compute a hash of the input string. Returns a new string with the binary data.

See descriptions of HashAlgorithm to learn of the supported digest size for each hash.

Do not use this for passwords#

None of these hashes are password hashing algorithms. They were designed to be fast to execute, whereas password hashing should never be fast. You shouldn't use this function for computing password hashes that will be stored, or for deriving keys from passwords.

NameTypeDefaultDescription
inputstringstring to compute the hash for
algorithmHashAlgorithmHashAlgorithm cryptographic hash function
Returns
  • string — String with the binary data of the hash

DecompressBuffer(input: buffer, algorithm: CompressionAlgorithm): buffer#

Safe

Decompresses the binary data stored in a buffer using the specified compression algorithm.

Decompression might throw an error if the compressed data doesn't contain expected decompressed size, if it is larger than 1GB or if it is invalid.

It is recommended to use EncodingService.GetDecompressedBufferSize to find out the decompressed data size before attempting to decompress. This is very important if the input buffer contents are outside of your control (for example, from a client RemoteEvent)

NameTypeDefaultDescription
inputbufferbuffer with compressed binary data
algorithmCompressionAlgorithmCompressionAlgorithm to use for decompression
Returns
  • buffer — buffer with the decompressed binary data

GetDecompressedBufferSize(input: buffer, algorithm: CompressionAlgorithm): int?#

Safe

Reports the size of the decompressed data stored in a compressed buffer. If the compressed data doesn't have a size or the size is corrupted or invalid (larger than 1GB), function returns nil. When a nil is returned, attempting to use EncodingService.DecompressBuffer on this buffer will throw an error.

NameTypeDefaultDescription
inputbufferbuffer with compressed binary data
algorithmCompressionAlgorithmCompressionAlgorithm used to compress it
Returns
  • int? — Integer size of the decompressed data or 'nil'

Inherited members#

Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed