Skip to content

Commit a67319e

Browse files
authored
Merge pull request #721 from zetashift/fix/file-api#601
Fixup `Blob` and `File` APIs
2 parents 927ac5d + 997e36f commit a67319e

File tree

9 files changed

+78
-5
lines changed

9 files changed

+78
-5
lines changed

api-reports/2_12.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ Blob[JC] def stream(): ReadableStream[Uint8Array]
373373
Blob[JC] def text(): js.Promise[String]
374374
Blob[JC] def `type`: String
375375
Blob[JO]
376-
BlobPropertyBag[JT] var endings: js.UndefOr[String]
376+
BlobPropertyBag[JT] var endings: js.UndefOr[EndingType]
377377
BlobPropertyBag[JT] var `type`: js.UndefOr[String]
378378
BlobPropertyBag[SO] def apply(`type`: js.UndefOr[String]?): BlobPropertyBag (@deprecated in 2.0.0)
379379
Body[JT] def arrayBuffer(): js.Promise[ArrayBuffer]
@@ -1801,6 +1801,9 @@ ElementDefinitionOptions[JT] var `extends`: js.UndefOr[String]
18011801
EndOfStreamError[JT]
18021802
EndOfStreamError[SO] val decode: EndOfStreamError
18031803
EndOfStreamError[SO] val network: EndOfStreamError
1804+
EndingType[JT]
1805+
EndingType[SO] val native: EndingType
1806+
EndingType[SO] val transparent: EndingType
18041807
ErrorEvent[JT] def bubbles: Boolean
18051808
ErrorEvent[JT] def cancelBubble: Boolean
18061809
ErrorEvent[JT] def cancelable: Boolean
@@ -1946,15 +1949,20 @@ FetchEventInit[JT] var request: js.UndefOr[Request]
19461949
FetchEventInit[JT] var scoped: js.UndefOr[Boolean]
19471950
File[JC] def arrayBuffer(): js.Promise[ArrayBuffer]
19481951
File[JC] def close(): Unit (@deprecated in 1.2.0)
1952+
File[JC] def lastModified: Double
19491953
File[JC] def name: String
19501954
File[JC] def size: Double
19511955
File[JC] def slice(start: Double?, end: Double?, contentType: String?): Blob
19521956
File[JC] def stream(): ReadableStream[Uint8Array]
19531957
File[JC] def text(): js.Promise[String]
19541958
File[JC] def `type`: String
1959+
File[JC] def webkitRelativePath: String
19551960
FileList[JC] @JSBracketAccess def apply(index: Int): T
19561961
FileList[JC] def item(index: Int): File
19571962
FileList[JC] def length: Int
1963+
FilePropertyBag[JT] var endings: js.UndefOr[EndingType]
1964+
FilePropertyBag[JT] var lastModified: js.UndefOr[Double]
1965+
FilePropertyBag[JT] var `type`: js.UndefOr[String]
19581966
FileReader[JC] def abort(): Unit
19591967
FileReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
19601968
FileReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
@@ -26925,6 +26933,7 @@ intl/NumberFormatOptions[JT] var useGrouping: js.UndefOr[Boolean]
2692526933
intl/NumberFormatOptions[SO] def apply(localeMatcher: js.UndefOr[String]?, style: js.UndefOr[String]?, currency: js.UndefOr[String]?, currencyDisplay: js.UndefOr[String]?, useGrouping: js.UndefOr[Boolean]?, minimumIntegerDigits: js.UndefOr[Double]?, minimumFractionDigits: js.UndefOr[Double]?, maximumFractionDigits: js.UndefOr[Double]?, minimumSignificantDigits: js.UndefOr[Double]?, maximumSignificantDigits: js.UndefOr[Double]?): NumberFormatOptions (@deprecated in 2.0.0)
2692626934
package[SO] type AlgorithmIdentifier = Algorithm | String
2692726935
package[SO] type BigInteger = js.typedarray.Uint8Array
26936+
package[SO] type BlobPart = BufferSource | Blob | String
2692826937
package[SO] type BodyInit = Blob | BufferSource | FormData | String | ReadableStream[Uint8Array] | URLSearchParams
2692926938
package[SO] type BufferSource = ArrayBufferView | ArrayBuffer
2693026939
package[SO] type ByteString = String

api-reports/2_13.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ Blob[JC] def stream(): ReadableStream[Uint8Array]
373373
Blob[JC] def text(): js.Promise[String]
374374
Blob[JC] def `type`: String
375375
Blob[JO]
376-
BlobPropertyBag[JT] var endings: js.UndefOr[String]
376+
BlobPropertyBag[JT] var endings: js.UndefOr[EndingType]
377377
BlobPropertyBag[JT] var `type`: js.UndefOr[String]
378378
BlobPropertyBag[SO] def apply(`type`: js.UndefOr[String]?): BlobPropertyBag (@deprecated in 2.0.0)
379379
Body[JT] def arrayBuffer(): js.Promise[ArrayBuffer]
@@ -1801,6 +1801,9 @@ ElementDefinitionOptions[JT] var `extends`: js.UndefOr[String]
18011801
EndOfStreamError[JT]
18021802
EndOfStreamError[SO] val decode: EndOfStreamError
18031803
EndOfStreamError[SO] val network: EndOfStreamError
1804+
EndingType[JT]
1805+
EndingType[SO] val native: EndingType
1806+
EndingType[SO] val transparent: EndingType
18041807
ErrorEvent[JT] def bubbles: Boolean
18051808
ErrorEvent[JT] def cancelBubble: Boolean
18061809
ErrorEvent[JT] def cancelable: Boolean
@@ -1946,15 +1949,20 @@ FetchEventInit[JT] var request: js.UndefOr[Request]
19461949
FetchEventInit[JT] var scoped: js.UndefOr[Boolean]
19471950
File[JC] def arrayBuffer(): js.Promise[ArrayBuffer]
19481951
File[JC] def close(): Unit (@deprecated in 1.2.0)
1952+
File[JC] def lastModified: Double
19491953
File[JC] def name: String
19501954
File[JC] def size: Double
19511955
File[JC] def slice(start: Double?, end: Double?, contentType: String?): Blob
19521956
File[JC] def stream(): ReadableStream[Uint8Array]
19531957
File[JC] def text(): js.Promise[String]
19541958
File[JC] def `type`: String
1959+
File[JC] def webkitRelativePath: String
19551960
FileList[JC] @JSBracketAccess def apply(index: Int): T
19561961
FileList[JC] def item(index: Int): File
19571962
FileList[JC] def length: Int
1963+
FilePropertyBag[JT] var endings: js.UndefOr[EndingType]
1964+
FilePropertyBag[JT] var lastModified: js.UndefOr[Double]
1965+
FilePropertyBag[JT] var `type`: js.UndefOr[String]
19581966
FileReader[JC] def abort(): Unit
19591967
FileReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
19601968
FileReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
@@ -26925,6 +26933,7 @@ intl/NumberFormatOptions[JT] var useGrouping: js.UndefOr[Boolean]
2692526933
intl/NumberFormatOptions[SO] def apply(localeMatcher: js.UndefOr[String]?, style: js.UndefOr[String]?, currency: js.UndefOr[String]?, currencyDisplay: js.UndefOr[String]?, useGrouping: js.UndefOr[Boolean]?, minimumIntegerDigits: js.UndefOr[Double]?, minimumFractionDigits: js.UndefOr[Double]?, maximumFractionDigits: js.UndefOr[Double]?, minimumSignificantDigits: js.UndefOr[Double]?, maximumSignificantDigits: js.UndefOr[Double]?): NumberFormatOptions (@deprecated in 2.0.0)
2692626934
package[SO] type AlgorithmIdentifier = Algorithm | String
2692726935
package[SO] type BigInteger = js.typedarray.Uint8Array
26936+
package[SO] type BlobPart = BufferSource | Blob | String
2692826937
package[SO] type BodyInit = Blob | BufferSource | FormData | String | ReadableStream[Uint8Array] | URLSearchParams
2692926938
package[SO] type BufferSource = ArrayBufferView | ArrayBuffer
2693026939
package[SO] type ByteString = String
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
/**
6+
* Endings enum for [[https://w3c.github.io/FileAPI/#enumdef-endingtype]]
7+
* If set to "native", line endings will be converted to native in any USVString elements in blobParts
8+
*/
9+
@js.native
10+
sealed trait EndingType extends js.Any
11+
12+
object EndingType {
13+
val transparent: EndingType = "transparent".asInstanceOf[EndingType]
14+
val native: EndingType = "native".asInstanceOf[EndingType]
15+
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
/**
6+
* Endings enum for [[https://w3c.github.io/FileAPI/#enumdef-endingtype]]
7+
* If set to "native", line endings will be converted to native in any USVString elements in blobParts
8+
*/
9+
opaque type EndingType <: String = String
10+
11+
object EndingType {
12+
val transparent: EndingType = "transparent"
13+
val native: EndingType = "native"
14+
}

dom/src/main/scala/org/scalajs/dom/Blob.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import scala.scalajs.js.typedarray.{ArrayBuffer, Uint8Array}
2323
*/
2424
@js.native
2525
@JSGlobal
26-
class Blob(blobParts: js.Array[js.Any] = js.native, options: BlobPropertyBag = js.native) extends js.Object {
26+
class Blob(blobParts: js.Iterable[BlobPart], options: BlobPropertyBag = js.native) extends js.Object {
2727

2828
@deprecated("This method seems to have been added in error and not actually exist.", "1.2.0")
2929
def close(): Unit = js.native

dom/src/main/scala/org/scalajs/dom/BlobPropertyBag.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import scala.scalajs.js
1111
trait BlobPropertyBag extends js.Object {
1212
var `type`: js.UndefOr[String] = js.undefined
1313

14-
var endings: js.UndefOr[String] = js.undefined
14+
var endings: js.UndefOr[EndingType] = js.undefined
1515
}
1616

1717
@deprecated("all members of BlobPropertyBag are deprecated", "2.0.0")

dom/src/main/scala/org/scalajs/dom/File.scala

+16-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,23 @@ import scala.scalajs.js.annotation._
1919
*/
2020
@js.native
2121
@JSGlobal
22-
abstract class File extends Blob {
22+
class File(bits: js.Iterable[BlobPart], _name: String, options: FilePropertyBag = js.native)
23+
extends Blob(bits, options) {
2324

2425
/** Returns the name of the file. For security reasons, the path is excluded from this property. */
2526
def name: String = js.native
27+
28+
/** The File.lastModified read-only property provides the last modified date of the file as the number of milliseconds
29+
* since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current
30+
* date.
31+
*/
32+
def lastModified: Double = js.native
33+
34+
/** The File.webkitRelativePath is a read-only property that contains a string which specifies the file's path
35+
* relative to the directory selected by the user in an <input> element with its webkitdirectory attribute set.
36+
*
37+
* @return
38+
* A string containing the path of the file relative to the ancestor directory the user selected.
39+
*/
40+
def webkitRelativePath: String = js.native
2641
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
/** An options object containing optional attributes for the file. */
6+
trait FilePropertyBag extends BlobPropertyBag {
7+
var lastModified: js.UndefOr[Double] = js.undefined
8+
}

dom/src/main/scala/org/scalajs/dom/package.scala

+2
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,6 @@ package object dom {
112112
@js.native
113113
@JSGlobal("crypto")
114114
val webcrypto: Crypto = js.native
115+
116+
type BlobPart = BufferSource | Blob | String
115117
}

0 commit comments

Comments
 (0)