-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbytes.go
More file actions
27 lines (22 loc) · 804 Bytes
/
bytes.go
File metadata and controls
27 lines (22 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//go:build js && wasm
package safejs
import (
"syscall/js"
"github.com/hack-pad/safejs/internal/catch"
)
// CopyBytesToGo copies bytes from src to dst.
// Returns the number of bytes copied, which is the minimum of the lengths of src and dst.
// Returns an error if src is not an Uint8Array or Uint8ClampedArray.
func CopyBytesToGo(dst []byte, src Value) (int, error) {
return catch.Try(func() int {
return js.CopyBytesToGo(dst, src.jsValue)
})
}
// CopyBytesToJS copies bytes from src to dst.
// Returns the number of bytes copied, which is the minimum of the lengths of src and dst.
// Returns an error if dst is not an Uint8Array or Uint8ClampedArray.
func CopyBytesToJS(dst Value, src []byte) (int, error) {
return catch.Try(func() int {
return js.CopyBytesToJS(dst.jsValue, src)
})
}