Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add BufferFromBase64 codec #181

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

pasalino
Copy link

I propose to add this codec. It is useful when you have a base64 string from external of your domain.
In this case, mainly if the string is long, it is very useful to use a Buffer instead of a string for at least two reasons:

  • if you have a base64 string and you move it within your domain, you copy the string many times, instead with Buffer you have a reference to pass between applications;
  • in this way you already parse a base64 string and you are sure that Buffer contains a valid array of bytes. Of course, you cannot be sure of the correctness of the contents, but you are sure of the correctness of the base64 string.
import { BufferFromBase64 } from 'io-ts-types/lib/BufferFromBase64'
import { right } from 'fp-ts/lib/Either'

const base64String = 'dGVzdCBvZiB0aGUgY29kZWM='
assert.deepStrictEqual(BufferFromBase64.decode(base64String), right(Buffer.from('test of the codec')))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant