Skip to content

Commit 69f46d5

Browse files
committed
Added FileReaderSync to dom.experimental
1 parent ee0bb77 commit 69f46d5

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.scalajs.dom.experimental
2+
3+
import org.scalajs.dom.raw.Blob
4+
5+
import scala.scalajs.js
6+
import scala.scalajs.js.annotation._
7+
import scala.scalajs.js.typedarray.ArrayBuffer
8+
9+
/**
10+
* The FileReaderSync interface allows to read File or Blob objects synchronously.
11+
*
12+
* This interface is only available in workers as it enables synchronous I/O that could potentially block.
13+
*
14+
* MDN
15+
*/
16+
@js.native
17+
@JSGlobal
18+
class FileReaderSync() extends js.Object {
19+
/**
20+
* The readAsArrayBuffer method is used to starts reading the contents of the
21+
* specified Blob or File. When the read operation is finished, the readyState
22+
* becomes DONE, and the loadend is triggered. At that time, the result attribute
23+
* contains an ArrayBuffer representing the file's data.
24+
*
25+
* MDN
26+
*/
27+
def readAsArrayBuffer(blob: Blob): ArrayBuffer = js.native
28+
29+
/**
30+
* The readAsDataURL method is used to starts reading the contents of the specified
31+
* Blob or File. When the read operation is finished, the readyState becomes DONE, and
32+
* the loadend is triggered. At that time, the result attribute contains a data: URL
33+
* representing the file's data as base64 encoded string.
34+
*
35+
* MDN
36+
*/
37+
def readAsDataURL(blob: Blob): URL = js.native
38+
39+
/**
40+
* The readAsText method is used to read the contents of the specified Blob or File.
41+
* When the read operation is complete, the readyState is changed to DONE, the loadend
42+
* is triggered, and the result attribute contains the contents of the file as a text string.
43+
*
44+
* MDN
45+
*/
46+
def readAsText(blob: Blob, encoding: String = "UTF-8"): String = js.native
47+
}

0 commit comments

Comments
 (0)