Skip to content

Commit 23c4c43

Browse files
committed
Added FileReaderSync to dom.experimental
1 parent ee0bb77 commit 23c4c43

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
/**
21+
* The readAsArrayBuffer method is used to starts reading the contents of the
22+
* specified Blob or File. When the read operation is finished, the readyState
23+
* becomes DONE, and the loadend is triggered. At that time, the result attribute
24+
* contains an ArrayBuffer representing the file's data.
25+
*
26+
* MDN
27+
*/
28+
def readAsArrayBuffer(blob: Blob): ArrayBuffer = js.native
29+
30+
/**
31+
* The readAsDataURL method is used to starts reading the contents of the specified
32+
* Blob or File. When the read operation is finished, the readyState becomes DONE, and
33+
* the loadend is triggered. At that time, the result attribute contains a data: URL
34+
* representing the file's data as base64 encoded string.
35+
*
36+
* MDN
37+
*/
38+
def readAsDataURL(blob: Blob): URL = js.native
39+
40+
/**
41+
* The readAsText method is used to read the contents of the specified Blob or File.
42+
* When the read operation is complete, the readyState is changed to DONE, the loadend
43+
* is triggered, and the result attribute contains the contents of the file as a text string.
44+
*
45+
* MDN
46+
*/
47+
def readAsText(blob: Blob, encoding: String = "UTF-8"): String = js.native
48+
}

0 commit comments

Comments
 (0)