-
-
Notifications
You must be signed in to change notification settings - Fork 42
Open
Description
Currently, we have:
Lines 2460 to 2465 in 662b7b8
| // 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)
Metadata
Metadata
Assignees
Labels
No labels