Currently, we have:
|
// File represents files as can be obtained from file choosers or drag |
|
// and drop. The dom package does not define any methods on File nor |
|
// does it provide access to the blob or a way to read it. |
|
type File struct { |
|
*js.Object |
|
} |
It might be helpful and worth considering changing it to have a Bytes() []byte method:
// File represents files as can be obtained from file choosers or drag
// and drop.
//
// Reference: https://developer.mozilla.org/en-US/docs/Web/API/File.
type File struct {
*js.Object
}
// Bytes reads the file f and returns its contents as a []byte.
func (f *File) Bytes() []byte {
b := make(chan []byte)
fr := js.Global.Get("FileReader").New()
fr.Set("onload", func() {
b <- js.Global.Get("Uint8Array").New(fr.Get("result")).Interface().([]byte)
})
fr.Call("readAsArrayBuffer", f.Object)
return <-b
}
(Extracted from gopherjs/gopherjs#776 and #32. /cc @inkeliz)
Currently, we have:
go-js-dom/dom.go
Lines 2460 to 2465 in 662b7b8
It might be helpful and worth considering changing it to have a
Bytes() []bytemethod:(Extracted from gopherjs/gopherjs#776 and #32. /cc @inkeliz)