From 56470f917b557ea1cc42e762ed64d629fb54d5c4 Mon Sep 17 00:00:00 2001 From: FabioPinheiro Date: Mon, 7 Oct 2019 19:36:16 +0100 Subject: [PATCH 1/3] Make Blob compliance with documentation --- src/main/scala/org/scalajs/dom/raw/lib.scala | 57 +++++++++++++++----- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/src/main/scala/org/scalajs/dom/raw/lib.scala b/src/main/scala/org/scalajs/dom/raw/lib.scala index 62d0e2dff..c3709853c 100644 --- a/src/main/scala/org/scalajs/dom/raw/lib.scala +++ b/src/main/scala/org/scalajs/dom/raw/lib.scala @@ -9,6 +9,8 @@ */ package org.scalajs.dom.raw +import org.scalajs.dom.experimental.ReadableStream + import scala.scalajs.js import scala.scalajs.js.annotation._ import scala.scalajs.js.typedarray.ArrayBuffer @@ -7970,14 +7972,18 @@ object BlobPropertyBag { } /** - * A Blob object represents a file-like object of immutable, raw data. Blobs - * represent data that isn't necessarily in a JavaScript-native format. The File - * interface is based on Blob, inheriting blob functionality and expanding it to - * support files on the user's system. + * A Blob object represents a file-like object of immutable, raw data; they can be + * read as text or binary data, or converted into a ReadableStream so its methods + * can be used for processing the data. Blobs can represent data that isn't + * necessarily in a JavaScript-native format. The File interface is based on Blob, + * inheriting blob functionality and expanding it to support files on the user's system. + * + * To construct a Blob from other non-blob objects and data, use the Blob() + * constructor. To create a blob that contains a subset of another blob's data, use the + * slice() method. To obtain a Blob object for a file on the user's file system, see + * the File documentation. * - * An easy way to construct a Blob is by invoking the Blob constuctor. Another - * way is to use the slice() method to create a blob that contains a subset of - * another blob's data. + * The APIs accepting Blob objects are also listed in the File documentation. * * MDN */ @@ -7987,8 +7993,6 @@ class Blob(blobParts: js.Array[js.Any] = js.native, options: BlobPropertyBag = js.native) extends js.Object { - def `type`: String = js.native - /** * The size, in bytes, of the data contained in the Blob object. * @@ -7997,15 +8001,44 @@ class Blob(blobParts: js.Array[js.Any] = js.native, def size: Double = js.native /** - * The slice is used to create a new Blob object containing the data in the specified - * range of bytes of the source Blob. + * A string indicating the MIME type of the data contained in the Blob. If the type + * is unknown, this string is empty. + * + * MDN + */ + def `type`: String = js.native + + /** + * A string indicating the MIME type of the data contained in the Blob. If the type + * is unknown, this string is empty. * * MDN */ def slice(start: Double = js.native, end: Double = js.native, contentType: String = js.native): Blob = js.native - def close(): Unit = js.native + /** + * Returns a ReadableStream that can be used to read the contents of the blob. + * + * MDN + */ + def stream(): ReadableStream[Byte] = js.native + + /** + * Returns a promise that resolves with a USVString containing the entire + * contents of the blob interpreted as UTF-8 text. + * + * MDN + * + * @see https://developer.mozilla.org/en-US/docs/Web/API/USVString + */ + def text(): scala.scalajs.js.Promise[String] = js.native + + /** + * Returns a promise that resolves with an ArrayBuffer containing the entire + * contents of the blob as binary data. + */ + def arrayBuffer(): scala.scalajs.js.Promise[ArrayBuffer] = js.native } @js.native From d3ef959168348ced31c6a0007fccbdb0c4a842d5 Mon Sep 17 00:00:00 2001 From: David Barri Date: Fri, 20 Aug 2021 10:35:29 +1000 Subject: [PATCH 2/3] sbt prePR --- api-reports/2_12.txt | 8 ++++++-- api-reports/2_13.txt | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index 33085d86c..c0aa40614 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -2534,9 +2534,11 @@ raw/BiquadFilterNode[JT] val numberOfOutputs: Int raw/BiquadFilterNode[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit raw/BiquadFilterNode[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit raw/BiquadFilterNode[JT] var `type`: String -raw/Blob[JC] def close(): Unit +raw/Blob[JC] def arrayBuffer(): scala.scalajs.js.Promise[ArrayBuffer] raw/Blob[JC] def size: Double raw/Blob[JC] def slice(start: Double?, end: Double?, contentType: String?): Blob +raw/Blob[JC] def stream(): ReadableStream[Byte] +raw/Blob[JC] def text(): scala.scalajs.js.Promise[String] raw/Blob[JC] def `type`: String raw/Blob[JO] raw/BlobPropertyBag[JT] def endings: String @@ -3770,10 +3772,12 @@ raw/EventTarget[JC] def dispatchEvent(evt: Event): Boolean raw/EventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit raw/EventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit raw/External[JT] -raw/File[JC] def close(): Unit +raw/File[JC] def arrayBuffer(): scala.scalajs.js.Promise[ArrayBuffer] raw/File[JC] def name: String raw/File[JC] def size: Double raw/File[JC] def slice(start: Double?, end: Double?, contentType: String?): Blob +raw/File[JC] def stream(): ReadableStream[Byte] +raw/File[JC] def text(): scala.scalajs.js.Promise[String] raw/File[JC] def `type`: String raw/FileList[JT] @scala.scalajs.js.annotation.JSBracketAccess def apply(index: Int): T raw/FileList[JT] def item(index: Int): T diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index 23b3e8b97..d5ffd2328 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -2534,9 +2534,11 @@ raw/BiquadFilterNode[JT] val numberOfOutputs: Int raw/BiquadFilterNode[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit raw/BiquadFilterNode[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit raw/BiquadFilterNode[JT] var `type`: String -raw/Blob[JC] def close(): Unit +raw/Blob[JC] def arrayBuffer(): scala.scalajs.js.Promise[ArrayBuffer] raw/Blob[JC] def size: Double raw/Blob[JC] def slice(start: Double?, end: Double?, contentType: String?): Blob +raw/Blob[JC] def stream(): ReadableStream[Byte] +raw/Blob[JC] def text(): scala.scalajs.js.Promise[String] raw/Blob[JC] def `type`: String raw/Blob[JO] raw/BlobPropertyBag[JT] def endings: String @@ -3770,10 +3772,12 @@ raw/EventTarget[JC] def dispatchEvent(evt: Event): Boolean raw/EventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit raw/EventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit raw/External[JT] -raw/File[JC] def close(): Unit +raw/File[JC] def arrayBuffer(): scala.scalajs.js.Promise[ArrayBuffer] raw/File[JC] def name: String raw/File[JC] def size: Double raw/File[JC] def slice(start: Double?, end: Double?, contentType: String?): Blob +raw/File[JC] def stream(): ReadableStream[Byte] +raw/File[JC] def text(): scala.scalajs.js.Promise[String] raw/File[JC] def `type`: String raw/FileList[JT] @scala.scalajs.js.annotation.JSBracketAccess def apply(index: Int): T raw/FileList[JT] def item(index: Int): T From 7b6bacaa296db0d05eb3b6de7fd4be40649fba9c Mon Sep 17 00:00:00 2001 From: David Barri Date: Fri, 20 Aug 2021 10:38:58 +1000 Subject: [PATCH 3/3] Restore close() for bincompat --- api-reports/2_12.txt | 10 ++++++---- api-reports/2_13.txt | 10 ++++++---- src/main/scala/org/scalajs/dom/raw/lib.scala | 10 +++++++--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index c0aa40614..446672788 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -2534,11 +2534,12 @@ raw/BiquadFilterNode[JT] val numberOfOutputs: Int raw/BiquadFilterNode[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit raw/BiquadFilterNode[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit raw/BiquadFilterNode[JT] var `type`: String -raw/Blob[JC] def arrayBuffer(): scala.scalajs.js.Promise[ArrayBuffer] +raw/Blob[JC] def arrayBuffer(): js.Promise[ArrayBuffer] +raw/Blob[JC] @deprecated("This method seems to have been added in error and not actually exist.", "1.2.0") def close(): Unit raw/Blob[JC] def size: Double raw/Blob[JC] def slice(start: Double?, end: Double?, contentType: String?): Blob raw/Blob[JC] def stream(): ReadableStream[Byte] -raw/Blob[JC] def text(): scala.scalajs.js.Promise[String] +raw/Blob[JC] def text(): js.Promise[String] raw/Blob[JC] def `type`: String raw/Blob[JO] raw/BlobPropertyBag[JT] def endings: String @@ -3772,12 +3773,13 @@ raw/EventTarget[JC] def dispatchEvent(evt: Event): Boolean raw/EventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit raw/EventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit raw/External[JT] -raw/File[JC] def arrayBuffer(): scala.scalajs.js.Promise[ArrayBuffer] +raw/File[JC] def arrayBuffer(): js.Promise[ArrayBuffer] +raw/File[JC] @deprecated("This method seems to have been added in error and not actually exist.", "1.2.0") def close(): Unit raw/File[JC] def name: String raw/File[JC] def size: Double raw/File[JC] def slice(start: Double?, end: Double?, contentType: String?): Blob raw/File[JC] def stream(): ReadableStream[Byte] -raw/File[JC] def text(): scala.scalajs.js.Promise[String] +raw/File[JC] def text(): js.Promise[String] raw/File[JC] def `type`: String raw/FileList[JT] @scala.scalajs.js.annotation.JSBracketAccess def apply(index: Int): T raw/FileList[JT] def item(index: Int): T diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index d5ffd2328..a9f7be132 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -2534,11 +2534,12 @@ raw/BiquadFilterNode[JT] val numberOfOutputs: Int raw/BiquadFilterNode[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit raw/BiquadFilterNode[JT] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit raw/BiquadFilterNode[JT] var `type`: String -raw/Blob[JC] def arrayBuffer(): scala.scalajs.js.Promise[ArrayBuffer] +raw/Blob[JC] def arrayBuffer(): js.Promise[ArrayBuffer] +raw/Blob[JC] @deprecated("This method seems to have been added in error and not actually exist.", "1.2.0") def close(): Unit raw/Blob[JC] def size: Double raw/Blob[JC] def slice(start: Double?, end: Double?, contentType: String?): Blob raw/Blob[JC] def stream(): ReadableStream[Byte] -raw/Blob[JC] def text(): scala.scalajs.js.Promise[String] +raw/Blob[JC] def text(): js.Promise[String] raw/Blob[JC] def `type`: String raw/Blob[JO] raw/BlobPropertyBag[JT] def endings: String @@ -3772,12 +3773,13 @@ raw/EventTarget[JC] def dispatchEvent(evt: Event): Boolean raw/EventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit raw/EventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit raw/External[JT] -raw/File[JC] def arrayBuffer(): scala.scalajs.js.Promise[ArrayBuffer] +raw/File[JC] def arrayBuffer(): js.Promise[ArrayBuffer] +raw/File[JC] @deprecated("This method seems to have been added in error and not actually exist.", "1.2.0") def close(): Unit raw/File[JC] def name: String raw/File[JC] def size: Double raw/File[JC] def slice(start: Double?, end: Double?, contentType: String?): Blob raw/File[JC] def stream(): ReadableStream[Byte] -raw/File[JC] def text(): scala.scalajs.js.Promise[String] +raw/File[JC] def text(): js.Promise[String] raw/File[JC] def `type`: String raw/FileList[JT] @scala.scalajs.js.annotation.JSBracketAccess def apply(index: Int): T raw/FileList[JT] def item(index: Int): T diff --git a/src/main/scala/org/scalajs/dom/raw/lib.scala b/src/main/scala/org/scalajs/dom/raw/lib.scala index f647581cb..a1bf2132a 100644 --- a/src/main/scala/org/scalajs/dom/raw/lib.scala +++ b/src/main/scala/org/scalajs/dom/raw/lib.scala @@ -10,7 +10,6 @@ package org.scalajs.dom.raw import org.scalajs.dom.experimental.ReadableStream - import scala.scalajs.js import scala.scalajs.js.annotation._ import scala.scalajs.js.typedarray.ArrayBuffer @@ -7862,6 +7861,11 @@ class Blob(blobParts: js.Array[js.Any] = js.native, 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 + /** * The size, in bytes, of the data contained in the Blob object. * @@ -7901,13 +7905,13 @@ class Blob(blobParts: js.Array[js.Any] = js.native, * * @see https://developer.mozilla.org/en-US/docs/Web/API/USVString */ - def text(): scala.scalajs.js.Promise[String] = js.native + def text(): js.Promise[String] = js.native /** * Returns a promise that resolves with an ArrayBuffer containing the entire * contents of the blob as binary data. */ - def arrayBuffer(): scala.scalajs.js.Promise[ArrayBuffer] = js.native + def arrayBuffer(): js.Promise[ArrayBuffer] = js.native } @js.native