Skip to content

Commit

Permalink
fix Node.Buffer.fromString signature, add all supported encodings (#…
Browse files Browse the repository at this point in the history
…1246)

* fix `Node.Buffer.fromString` signature, add all supported encodings

* chore: add changelog entry
  • Loading branch information
anmonteiro authored Dec 8, 2024
1 parent ae702a7 commit 8a60298
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ Unreleased
([#1222](https://github.com/melange-re/melange/pull/1222))
- melange-ppx: allow `@mel.unwrap` polyvariants not to have a payload
([#1239](https://github.com/melange-re/melange/pull/1239))
- `melange.node`: fix `Buffer.fromString` and add
`Buffer.fromStringWithEncoding`
([#1246](https://github.com/melange-re/melange/pull/1246))
- `melange.node`: bind to all supported Node.js `Buffer` encodings in
`Node.Buffer` ([#1246](https://github.com/melange-re/melange/pull/1246))

4.0.1 2024-06-07
---------------
Expand Down
13 changes: 11 additions & 2 deletions jscomp/others/node_buffer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@
type t = Node.buffer

type encoding =
[ `ascii | `utf8 | `utf16le | `usc2 | `base64 | `latin1 | `binary | `hex ]
[ `ascii
| `utf8
| `utf16le
| `ucs2
| `base64
| `base64url
| `latin1
| `binary
| `hex ]

external isBuffer : 'a -> bool = "isBuffer" [@@mel.scope "Buffer"]
external fromString : string -> t = "from" [@@mel.scope "Buffer"]

external fromString : ?encoding:encoding -> string -> t = "from"
external fromStringWithEncoding : string -> encoding:encoding -> t = "from"
[@@mel.scope "Buffer"]

external toString : ?encoding:encoding -> string = "toString"
Expand Down

0 comments on commit 8a60298

Please sign in to comment.