Skip to content

Fixup Blob and File APIs #721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion api-reports/2_12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Blob[JC] def stream(): ReadableStream[Uint8Array]
Blob[JC] def text(): js.Promise[String]
Blob[JC] def `type`: String
Blob[JO]
BlobPropertyBag[JT] var endings: js.UndefOr[String]
BlobPropertyBag[JT] var endings: js.UndefOr[EndingType]
BlobPropertyBag[JT] var `type`: js.UndefOr[String]
BlobPropertyBag[SO] def apply(`type`: js.UndefOr[String]?): BlobPropertyBag (@deprecated in 2.0.0)
Body[JT] def arrayBuffer(): js.Promise[ArrayBuffer]
Expand Down Expand Up @@ -1801,6 +1801,9 @@ ElementDefinitionOptions[JT] var `extends`: js.UndefOr[String]
EndOfStreamError[JT]
EndOfStreamError[SO] val decode: EndOfStreamError
EndOfStreamError[SO] val network: EndOfStreamError
EndingType[JT]
EndingType[SO] val native: EndingType
EndingType[SO] val transparent: EndingType
ErrorEvent[JT] def bubbles: Boolean
ErrorEvent[JT] def cancelBubble: Boolean
ErrorEvent[JT] def cancelable: Boolean
Expand Down Expand Up @@ -1946,15 +1949,20 @@ FetchEventInit[JT] var request: js.UndefOr[Request]
FetchEventInit[JT] var scoped: js.UndefOr[Boolean]
File[JC] def arrayBuffer(): js.Promise[ArrayBuffer]
File[JC] def close(): Unit (@deprecated in 1.2.0)
File[JC] def lastModified: Double
File[JC] def name: String
File[JC] def size: Double
File[JC] def slice(start: Double?, end: Double?, contentType: String?): Blob
File[JC] def stream(): ReadableStream[Uint8Array]
File[JC] def text(): js.Promise[String]
File[JC] def `type`: String
File[JC] def webkitRelativePath: String
FileList[JC] @JSBracketAccess def apply(index: Int): T
FileList[JC] def item(index: Int): File
FileList[JC] def length: Int
FilePropertyBag[JT] var endings: js.UndefOr[EndingType]
FilePropertyBag[JT] var lastModified: js.UndefOr[Double]
FilePropertyBag[JT] var `type`: js.UndefOr[String]
FileReader[JC] def abort(): Unit
FileReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
FileReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
Expand Down Expand Up @@ -26925,6 +26933,7 @@ intl/NumberFormatOptions[JT] var useGrouping: js.UndefOr[Boolean]
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)
package[SO] type AlgorithmIdentifier = Algorithm | String
package[SO] type BigInteger = js.typedarray.Uint8Array
package[SO] type BlobPart = BufferSource | Blob | String
package[SO] type BodyInit = Blob | BufferSource | FormData | String | ReadableStream[Uint8Array] | URLSearchParams
package[SO] type BufferSource = ArrayBufferView | ArrayBuffer
package[SO] type ByteString = String
Expand Down
11 changes: 10 additions & 1 deletion api-reports/2_13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Blob[JC] def stream(): ReadableStream[Uint8Array]
Blob[JC] def text(): js.Promise[String]
Blob[JC] def `type`: String
Blob[JO]
BlobPropertyBag[JT] var endings: js.UndefOr[String]
BlobPropertyBag[JT] var endings: js.UndefOr[EndingType]
BlobPropertyBag[JT] var `type`: js.UndefOr[String]
BlobPropertyBag[SO] def apply(`type`: js.UndefOr[String]?): BlobPropertyBag (@deprecated in 2.0.0)
Body[JT] def arrayBuffer(): js.Promise[ArrayBuffer]
Expand Down Expand Up @@ -1801,6 +1801,9 @@ ElementDefinitionOptions[JT] var `extends`: js.UndefOr[String]
EndOfStreamError[JT]
EndOfStreamError[SO] val decode: EndOfStreamError
EndOfStreamError[SO] val network: EndOfStreamError
EndingType[JT]
EndingType[SO] val native: EndingType
EndingType[SO] val transparent: EndingType
ErrorEvent[JT] def bubbles: Boolean
ErrorEvent[JT] def cancelBubble: Boolean
ErrorEvent[JT] def cancelable: Boolean
Expand Down Expand Up @@ -1946,15 +1949,20 @@ FetchEventInit[JT] var request: js.UndefOr[Request]
FetchEventInit[JT] var scoped: js.UndefOr[Boolean]
File[JC] def arrayBuffer(): js.Promise[ArrayBuffer]
File[JC] def close(): Unit (@deprecated in 1.2.0)
File[JC] def lastModified: Double
File[JC] def name: String
File[JC] def size: Double
File[JC] def slice(start: Double?, end: Double?, contentType: String?): Blob
File[JC] def stream(): ReadableStream[Uint8Array]
File[JC] def text(): js.Promise[String]
File[JC] def `type`: String
File[JC] def webkitRelativePath: String
FileList[JC] @JSBracketAccess def apply(index: Int): T
FileList[JC] def item(index: Int): File
FileList[JC] def length: Int
FilePropertyBag[JT] var endings: js.UndefOr[EndingType]
FilePropertyBag[JT] var lastModified: js.UndefOr[Double]
FilePropertyBag[JT] var `type`: js.UndefOr[String]
FileReader[JC] def abort(): Unit
FileReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
FileReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
Expand Down Expand Up @@ -26925,6 +26933,7 @@ intl/NumberFormatOptions[JT] var useGrouping: js.UndefOr[Boolean]
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)
package[SO] type AlgorithmIdentifier = Algorithm | String
package[SO] type BigInteger = js.typedarray.Uint8Array
package[SO] type BlobPart = BufferSource | Blob | String
package[SO] type BodyInit = Blob | BufferSource | FormData | String | ReadableStream[Uint8Array] | URLSearchParams
package[SO] type BufferSource = ArrayBufferView | ArrayBuffer
package[SO] type ByteString = String
Expand Down
16 changes: 16 additions & 0 deletions dom/src/main/scala-2/org/scalajs/dom/EndingType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.scalajs.dom

import scala.scalajs.js

/**
* Endings enum for [[https://w3c.github.io/FileAPI/#enumdef-endingtype]]
* If set to "native", line endings will be converted to native in any USVString elements in blobParts
*/
@js.native
sealed trait EndingType extends js.Any

object EndingType {
val transparent: EndingType = "transparent".asInstanceOf[EndingType]
val native: EndingType = "native".asInstanceOf[EndingType]

}
14 changes: 14 additions & 0 deletions dom/src/main/scala-3/org/scalajs/dom/EndingType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.scalajs.dom

import scala.scalajs.js

/**
* Endings enum for [[https://w3c.github.io/FileAPI/#enumdef-endingtype]]
* If set to "native", line endings will be converted to native in any USVString elements in blobParts
*/
opaque type EndingType <: String = String

object EndingType {
val transparent: EndingType = "transparent"
val native: EndingType = "native"
}
2 changes: 1 addition & 1 deletion dom/src/main/scala/org/scalajs/dom/Blob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import scala.scalajs.js.typedarray.{ArrayBuffer, Uint8Array}
*/
@js.native
@JSGlobal
class Blob(blobParts: js.Array[js.Any] = js.native, options: BlobPropertyBag = js.native) extends js.Object {
class Blob(blobParts: js.Iterable[BlobPart], options: BlobPropertyBag = js.native) extends js.Object {

@deprecated("This method seems to have been added in error and not actually exist.", "1.2.0")
def close(): Unit = js.native
Expand Down
2 changes: 1 addition & 1 deletion dom/src/main/scala/org/scalajs/dom/BlobPropertyBag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import scala.scalajs.js
trait BlobPropertyBag extends js.Object {
var `type`: js.UndefOr[String] = js.undefined

var endings: js.UndefOr[String] = js.undefined
var endings: js.UndefOr[EndingType] = js.undefined
}

@deprecated("all members of BlobPropertyBag are deprecated", "2.0.0")
Expand Down
17 changes: 16 additions & 1 deletion dom/src/main/scala/org/scalajs/dom/File.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,23 @@ import scala.scalajs.js.annotation._
*/
@js.native
@JSGlobal
abstract class File extends Blob {
class File(bits: js.Iterable[BlobPart], _name: String, options: FilePropertyBag = js.native)
extends Blob(bits, options) {

/** Returns the name of the file. For security reasons, the path is excluded from this property. */
def name: String = js.native

/** The File.lastModified read-only property provides the last modified date of the file as the number of milliseconds
* since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current
* date.
*/
def lastModified: Double = js.native

/** The File.webkitRelativePath is a read-only property that contains a string which specifies the file's path
* relative to the directory selected by the user in an <input> element with its webkitdirectory attribute set.
*
* @return
* A string containing the path of the file relative to the ancestor directory the user selected.
*/
def webkitRelativePath: String = js.native
}
8 changes: 8 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/FilePropertyBag.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.scalajs.dom

import scala.scalajs.js

/** An options object containing optional attributes for the file. */
trait FilePropertyBag extends BlobPropertyBag {
var lastModified: js.UndefOr[Double] = js.undefined
}
2 changes: 2 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,6 @@ package object dom {
@js.native
@JSGlobal("crypto")
val webcrypto: Crypto = js.native

type BlobPart = BufferSource | Blob | String
}