diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index bf03dfdaa..8fbe43785 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -2293,6 +2293,39 @@ FileReader[JO] val LOADING: Short FileReaderSync[JC] def readAsArrayBuffer(blob: Blob): ArrayBuffer FileReaderSync[JC] def readAsDataURL(blob: Blob): URL FileReaderSync[JC] def readAsText(blob: Blob, encoding: String?): String +FileSystemCreateWritableOptions[JT] var keepExistingData: js.UndefOr[Boolean] +FileSystemDirectoryHandle[JT] def getDirectoryHandle(name: String, options: js.UndefOr[FileSystemGetDirectoryOptions]?): js.Promise[FileSystemDirectoryHandle] +FileSystemDirectoryHandle[JT] def getFileHandle(name: String, options: js.UndefOr[FileSystemGetFileOptions]?): js.Promise[FileSystemFileHandle] +FileSystemDirectoryHandle[JT] def isSameEntry(fileSystemHandle: FileSystemHandle): js.Promise[Boolean] +FileSystemDirectoryHandle[JT] val kind: FileSystemHandleKind +FileSystemDirectoryHandle[JT] def name: String +FileSystemDirectoryHandle[JT] def removeEntry(name: String, options: js.UndefOr[FileSystemRemoveOptions]?): js.Promise[Unit] +FileSystemDirectoryHandle[JT] def resolve(possibleDescendant: FileSystemHandle): js.Promise[js.Array[String]] +FileSystemFileHandle[JT] def createSyncAccessHandle(): js.Promise[FileSystemSyncAccessHandle] +FileSystemFileHandle[JT] def createWritable(options: js.UndefOr[FileSystemCreateWritableOptions]?): js.Promise[FileSystemWritableFileStream] +FileSystemFileHandle[JT] def getFile(): js.Promise[File] +FileSystemGetDirectoryOptions[JT] var create: js.UndefOr[Boolean] +FileSystemGetFileOptions[JT] var create: js.UndefOr[Boolean] +FileSystemHandle[JT] def isSameEntry(fileSystemHandle: FileSystemHandle): js.Promise[Boolean] +FileSystemHandle[JT] val kind: FileSystemHandleKind +FileSystemHandle[JT] def name: String +FileSystemHandleKind[JT] +FileSystemHandleKind[SO] val directory: FileSystemHandleKind +FileSystemHandleKind[SO] val file: FileSystemHandleKind +FileSystemReadWriteOptions[JT] var at: Double +FileSystemRemoveOptions[JT] var recursive: js.UndefOr[Boolean] +FileSystemSyncAccessHandle[JT] def close(): Unit +FileSystemSyncAccessHandle[JT] def flush(): Unit +FileSystemSyncAccessHandle[JT] def getSize(): Double +FileSystemSyncAccessHandle[JT] def read(buffer: BufferSource, options: js.UndefOr[FileSystemReadWriteOptions]?): Double +FileSystemSyncAccessHandle[JT] def truncate(newSize: Double): Unit +FileSystemSyncAccessHandle[JT] def write(buffer: BufferSource, options: js.UndefOr[FileSystemReadWriteOptions]?): Double +FileSystemWritableFileStream[JT] def seek(position: Double): js.Promise[Unit] +FileSystemWritableFileStream[JT] def truncate(size: Double): js.Promise[Unit] +FileSystemWritableFileStream[JT] def write(data: Blob): js.Promise[Unit] +FileSystemWritableFileStream[JT] def write(data: BufferSource): js.Promise[Unit] +FileSystemWritableFileStream[JT] def write(data: String): js.Promise[Unit] +FileSystemWritableFileStream[JT] def write(data: WriteParams): js.Promise[Unit] FocusEvent[JC] def bubbles: Boolean FocusEvent[JC] def cancelBubble: Boolean FocusEvent[JC] def cancelable: Boolean @@ -26374,6 +26407,7 @@ StorageEventInit[JT] var scoped: js.UndefOr[Boolean] StorageEventInit[JT] var storageArea: js.UndefOr[Storage] StorageEventInit[JT] var url: js.UndefOr[String] StorageManager[JT] def estimate(): js.Promise[StorageEstimate] +StorageManager[JT] def getDirectory(): js.Promise[FileSystemDirectoryHandle] StorageManager[JT] def persist(): js.Promise[Boolean] StorageManager[JT] def persisted(): js.Promise[Boolean] StyleMedia[JT] def matchMedium(mediaquery: String): Boolean @@ -27574,6 +27608,14 @@ WorkerOptions[JT] var `type`: js.UndefOr[WorkerType] WorkerType[JT] WorkerType[SO] val classic: WorkerType WorkerType[SO] val module: WorkerType +WriteCommandType[JT] +WriteCommandType[SO] val seek: WriteCommandType +WriteCommandType[SO] val truncate: WriteCommandType +WriteCommandType[SO] val write: WriteCommandType +WriteParams[JT] var data: js.UndefOr[BufferSource | Blob | String] +WriteParams[JT] var position: js.UndefOr[Double] +WriteParams[JT] var size: js.UndefOr[Double] +WriteParams[JT] var `type`: WriteCommandType WriteableState[JT] WriteableState[SO] val closed: WriteableState WriteableState[SO] val closing: WriteableState diff --git a/dom/src/main/scala-2/org/scalajs/dom/FileSystemHandleKind.scala b/dom/src/main/scala-2/org/scalajs/dom/FileSystemHandleKind.scala new file mode 100644 index 000000000..c2fdfcf25 --- /dev/null +++ b/dom/src/main/scala-2/org/scalajs/dom/FileSystemHandleKind.scala @@ -0,0 +1,11 @@ +package org.scalajs.dom + +import scala.scalajs.js + +@js.native +sealed trait FileSystemHandleKind extends js.Any + +object FileSystemHandleKind { + val file: FileSystemHandleKind = "file".asInstanceOf[FileSystemHandleKind] + val directory: FileSystemHandleKind = "directory".asInstanceOf[FileSystemHandleKind] +} diff --git a/dom/src/main/scala-2/org/scalajs/dom/WriteCommandType.scala b/dom/src/main/scala-2/org/scalajs/dom/WriteCommandType.scala new file mode 100644 index 000000000..a4500df59 --- /dev/null +++ b/dom/src/main/scala-2/org/scalajs/dom/WriteCommandType.scala @@ -0,0 +1,12 @@ +package org.scalajs.dom + +import scala.scalajs.js + +@js.native +sealed trait WriteCommandType extends js.Any + +object WriteCommandType { + val write: WriteCommandType = "write".asInstanceOf[WriteCommandType] + val seek: WriteCommandType = "seek".asInstanceOf[WriteCommandType] + val truncate: WriteCommandType = "truncate".asInstanceOf[WriteCommandType] +} diff --git a/dom/src/main/scala-3/org/scalajs/dom/FileSystemHandleKind.scala b/dom/src/main/scala-3/org/scalajs/dom/FileSystemHandleKind.scala new file mode 100644 index 000000000..dc75561fc --- /dev/null +++ b/dom/src/main/scala-3/org/scalajs/dom/FileSystemHandleKind.scala @@ -0,0 +1,10 @@ +package org.scalajs.dom + +import scala.scalajs.js + +opaque type FileSystemHandleKind <: String = String + +object FileSystemHandleKind { + val file: FileSystemHandleKind = "file" + val directory: FileSystemHandleKind = "directory" +} diff --git a/dom/src/main/scala-3/org/scalajs/dom/WriteCommandType.scala b/dom/src/main/scala-3/org/scalajs/dom/WriteCommandType.scala new file mode 100644 index 000000000..23433218b --- /dev/null +++ b/dom/src/main/scala-3/org/scalajs/dom/WriteCommandType.scala @@ -0,0 +1,11 @@ +package org.scalajs.dom + +import scala.scalajs.js + +opaque type WriteCommandType <: String = String + +object WriteCommandType { + val write: WriteCommandType = "write" + val seek: WriteCommandType = "seek" + val truncate: WriteCommandType = "truncate" +} diff --git a/dom/src/main/scala/org/scalajs/dom/FileSystemCreateWritableOptions.scala b/dom/src/main/scala/org/scalajs/dom/FileSystemCreateWritableOptions.scala new file mode 100644 index 000000000..8524c7741 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/FileSystemCreateWritableOptions.scala @@ -0,0 +1,17 @@ +/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API + * and available under the Creative Commons Attribution-ShareAlike v2.5 or later. + * http://creativecommons.org/licenses/by-sa/2.5/ + * + * Everything else is under the MIT License http://opensource.org/licenses/MIT + */ +package org.scalajs.dom + +import scala.scalajs.js + +trait FileSystemCreateWritableOptions extends js.Object { + + /** A Boolean. Default false. When set to true if the file exists, the existing file is first copied to the temporary + * file. Otherwise the temporary file starts out empty. + */ + var keepExistingData: js.UndefOr[Boolean] = js.undefined +} diff --git a/dom/src/main/scala/org/scalajs/dom/FileSystemDirectoryHandle.scala b/dom/src/main/scala/org/scalajs/dom/FileSystemDirectoryHandle.scala new file mode 100644 index 000000000..b25065a46 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/FileSystemDirectoryHandle.scala @@ -0,0 +1,67 @@ +/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API + * and available under the Creative Commons Attribution-ShareAlike v2.5 or later. + * http://creativecommons.org/licenses/by-sa/2.5/ + * + * Everything else is under the MIT License http://opensource.org/licenses/MIT + */ +package org.scalajs.dom + +import scala.scalajs.js + +/** The FileSystemDirectoryHandle interface of the File System API provides a handle to a file system directory. */ +@js.native +trait FileSystemDirectoryHandle extends FileSystemHandle { + + /** The getDirectoryHandle() method of the FileSystemDirectoryHandle interface returns a FileSystemDirectoryHandle for + * a subdirectory with the specified name within the directory handle on which the method is called. + * + * @param name + * A string representing the FileSystemHandle.name of the file you wish to retrieve. + * @param options + * An optional object containing options for the retrieved subdirectory. + * + * @return + * A Promise which resolves with a FileSystemDirectoryHandle. + */ + def getDirectoryHandle(name: String, + options: js.UndefOr[FileSystemGetDirectoryOptions] = js.native): js.Promise[FileSystemDirectoryHandle] = js.native + + /** The getFileHandle() method of the FileSystemDirectoryHandle interface returns a FileSystemFileHandle for a file + * with the specified name, within the directory the method is called. + * + * @param name + * A string representing the FileSystemHandle.name of the subdirectory you wish to retrieve. + * @param options + * An object. + * + * @return + * A Promise which resolves with a FileSystemFileHandle. + */ + def getFileHandle(name: String, + options: js.UndefOr[FileSystemGetFileOptions] = js.native): js.Promise[FileSystemFileHandle] = js.native + + /** The removeEntry() method of the FileSystemDirectoryHandle interface attempts to remove an entry if the directory + * handle contains a file or directory called the name specified. + * + * @param name + * A string representing the FileSystemHandle.name of the entry you wish to remove. + * @param options + * An optional object containing options + * + * @return + * A Promise which resolves with undefined. + */ + def removeEntry(name: String, options: js.UndefOr[FileSystemRemoveOptions] = js.native): js.Promise[Unit] = js.native + + /** The resolve() method of the FileSystemDirectoryHandle interface returns an Array of directory names from the + * parent handle to the specified child entry, with the name of the child entry as the last array item. + * + * @param possibleDescendant + * The FileSystemHandle from which to return the relative path. + * + * @return + * A Promise which resolves with an Array of strings, or null if possibleDescendant is not a descendant of this + * FileSystemDirectoryHandle. + */ + def resolve(possibleDescendant: FileSystemHandle): js.Promise[js.Array[String]] = js.native +} diff --git a/dom/src/main/scala/org/scalajs/dom/FileSystemFileHandle.scala b/dom/src/main/scala/org/scalajs/dom/FileSystemFileHandle.scala new file mode 100644 index 000000000..c35d7bbd4 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/FileSystemFileHandle.scala @@ -0,0 +1,61 @@ +/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API + * and available under the Creative Commons Attribution-ShareAlike v2.5 or later. + * http://creativecommons.org/licenses/by-sa/2.5/ + * + * Everything else is under the MIT License http://opensource.org/licenses/MIT + */ +package org.scalajs.dom + +import scala.scalajs.js + +/** The FileSystemFileHandle interface of the File System API represents a handle to a file system entry. The interface + * is accessed through the window.showOpenFilePicker() method. + * + * Note that read and write operations depend on file-access permissions that do not persist after a page refresh if no + * other tabs for that origin remain open. The queryPermission method of the FileSystemHandle interface can be used to + * verify permission state before accessing a file. + */ +@js.native +trait FileSystemFileHandle extends js.Object { + + /** The getFile() method of the FileSystemFileHandle interface returns a Promise which resolves to a File object + * representing the state on disk of the entry represented by the handle. + * + * If the file on disk changes or is removed after this method is called, the returned File object will likely be no + * longer readable. + * + * @return + * A Promise which resolves to a File object. + */ + def getFile(): js.Promise[File] = js.native + + /** The createSyncAccessHandle() method of the FileSystemFileHandle interface returns a Promise which resolves to a + * FileSystemSyncAccessHandle object that can be used to synchronously read from and write to a file. The synchronous + * nature of this method brings performance advantages, but it is only usable inside dedicated Web Workers for files + * within the origin private file system. + * + * Creating a FileSystemSyncAccessHandle takes an exclusive lock on the file associated with the file handle. This + * prevents the creation of further FileSystemSyncAccessHandles or FileSystemWritableFileStreams for the file until + * the existing access handle is closed. + * + * @return + * A Promise which resolves to a FileSystemSyncAccessHandle object. + */ + def createSyncAccessHandle(): js.Promise[FileSystemSyncAccessHandle] = js.native + + /** The createWritable() method of the FileSystemFileHandle interface creates a FileSystemWritableFileStream that can + * be used to write to a file. The method returns a Promise which resolves to this created stream. + * + * Any changes made through the stream won't be reflected in the file represented by the file handle until the stream + * has been closed. This is typically implemented by writing data to a temporary file, and only replacing the file + * represented by file handle with the temporary file when the writable filestream is closed. + * + * @param options + * An object. + * + * @return + * A Promise which resolves to a FileSystemWritableFileStream object. + */ + def createWritable( + options: js.UndefOr[FileSystemCreateWritableOptions] = js.native): js.Promise[FileSystemWritableFileStream] = js.native +} diff --git a/dom/src/main/scala/org/scalajs/dom/FileSystemGetDirectoryOptions.scala b/dom/src/main/scala/org/scalajs/dom/FileSystemGetDirectoryOptions.scala new file mode 100644 index 000000000..5271aaee3 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/FileSystemGetDirectoryOptions.scala @@ -0,0 +1,17 @@ +/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API + * and available under the Creative Commons Attribution-ShareAlike v2.5 or later. + * http://creativecommons.org/licenses/by-sa/2.5/ + * + * Everything else is under the MIT License http://opensource.org/licenses/MIT + */ +package org.scalajs.dom + +import scala.scalajs.js + +trait FileSystemGetDirectoryOptions extends js.Object { + + /** A boolean value, which defaults to false. When set to true if the directory is not found, one with the specified + * name will be created and returned. + */ + var create: js.UndefOr[Boolean] = js.undefined +} diff --git a/dom/src/main/scala/org/scalajs/dom/FileSystemGetFileOptions.scala b/dom/src/main/scala/org/scalajs/dom/FileSystemGetFileOptions.scala new file mode 100644 index 000000000..2c39f3adb --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/FileSystemGetFileOptions.scala @@ -0,0 +1,17 @@ +/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API + * and available under the Creative Commons Attribution-ShareAlike v2.5 or later. + * http://creativecommons.org/licenses/by-sa/2.5/ + * + * Everything else is under the MIT License http://opensource.org/licenses/MIT + */ +package org.scalajs.dom + +import scala.scalajs.js + +trait FileSystemGetFileOptions extends js.Object { + + /** A Boolean. Default false. When set to true if the file is not found, one with the specified name will be created + * and returned. + */ + var create: js.UndefOr[Boolean] = js.undefined +} diff --git a/dom/src/main/scala/org/scalajs/dom/FileSystemHandle.scala b/dom/src/main/scala/org/scalajs/dom/FileSystemHandle.scala new file mode 100644 index 000000000..a6ad25c59 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/FileSystemHandle.scala @@ -0,0 +1,34 @@ +/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API + * and available under the Creative Commons Attribution-ShareAlike v2.5 or later. + * http://creativecommons.org/licenses/by-sa/2.5/ + * + * Everything else is under the MIT License http://opensource.org/licenses/MIT + */ +package org.scalajs.dom + +import scala.scalajs.js + +/** The FileSystemHandle interface of the File System API is an object which represents a file or directory entry. + * Multiple handles can represent the same entry. For the most part you do not work with FileSystemHandle directly but + * rather its child interfaces FileSystemFileHandle and FileSystemDirectoryHandle. + */ +@js.native +trait FileSystemHandle extends js.Object { + + /** Returns the type of entry. This is 'file' if the associated entry is a file or 'directory'. */ + val kind: FileSystemHandleKind = js.native + + /** Returns the name of the associated entry. */ + def name: String = js.native + + /** The isSameEntry() method of the FileSystemHandle interface compares two handles to see if the associated entries + * (either a file or directory) match. + * + * @param fileSystemHandle + * The FileSystemHandle to match against the handle on which the method is invoked. + * + * @return + * A Promise that fulfills with a Boolean. + */ + def isSameEntry(fileSystemHandle: FileSystemHandle): js.Promise[Boolean] = js.native +} diff --git a/dom/src/main/scala/org/scalajs/dom/FileSystemReadWriteOptions.scala b/dom/src/main/scala/org/scalajs/dom/FileSystemReadWriteOptions.scala new file mode 100644 index 000000000..59898b85a --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/FileSystemReadWriteOptions.scala @@ -0,0 +1,17 @@ +/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API + * and available under the Creative Commons Attribution-ShareAlike v2.5 or later. + * http://creativecommons.org/licenses/by-sa/2.5/ + * + * Everything else is under the MIT License http://opensource.org/licenses/MIT + */ +package org.scalajs.dom + +import scala.scalajs.js + +trait FileSystemReadWriteOptions extends js.Object { + + /** A number representing the offset in bytes from the start of the file that the file should be read from or written + * at. + */ + var at: Double +} diff --git a/dom/src/main/scala/org/scalajs/dom/FileSystemRemoveOptions.scala b/dom/src/main/scala/org/scalajs/dom/FileSystemRemoveOptions.scala new file mode 100644 index 000000000..9dff814f8 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/FileSystemRemoveOptions.scala @@ -0,0 +1,15 @@ +/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API + * and available under the Creative Commons Attribution-ShareAlike v2.5 or later. + * http://creativecommons.org/licenses/by-sa/2.5/ + * + * Everything else is under the MIT License http://opensource.org/licenses/MIT + */ +package org.scalajs.dom + +import scala.scalajs.js + +trait FileSystemRemoveOptions extends js.Object { + + /** A boolean value, which defaults to false. When set to true entries will be removed recursively. */ + var recursive: js.UndefOr[Boolean] = js.undefined +} diff --git a/dom/src/main/scala/org/scalajs/dom/FileSystemSyncAccessHandle.scala b/dom/src/main/scala/org/scalajs/dom/FileSystemSyncAccessHandle.scala new file mode 100644 index 000000000..6c3435a68 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/FileSystemSyncAccessHandle.scala @@ -0,0 +1,87 @@ +/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API + * and available under the Creative Commons Attribution-ShareAlike v2.5 or later. + * http://creativecommons.org/licenses/by-sa/2.5/ + * + * Everything else is under the MIT License http://opensource.org/licenses/MIT + */ +package org.scalajs.dom + +import scala.scalajs.js + +/** The FileSystemSyncAccessHandle interface of the File System API represents a synchronous handle to a file system + * entry. + * + * This class is only accessible inside dedicated Web Workers (so that its methods do not block execution on the main + * thread) for files within the origin private file system, which is not visible to end-users. + * + * As a result, its methods are not subject to the same security checks as methods running on files within the + * user-visible file system, and so are much more performant. This makes them suitable for significant, large-scale + * file updates such as SQLite database modifications. + * + * The interface is accessed through the FileSystemFileHandle.createSyncAccessHandle() method. + */ +@js.native +trait FileSystemSyncAccessHandle extends js.Object { + + /** The close() method of the FileSystemSyncAccessHandle interface closes an open synchronous file handle, disabling + * any further operations on it and releasing the exclusive lock previously put on the file associated with the file + * handle. + */ + def close(): Unit = js.native + + /** The flush() method of the FileSystemSyncAccessHandle interface persists any changes made to the file associated + * with the handle via the write() method to disk. + * + * Bear in mind that you only need to call this method if you need the changes committed to disk at a specific time, + * otherwise you can leave the underlying operating system to handle this when it sees fit, which should be OK in + * most cases. + */ + def flush(): Unit = js.native + + /** The getSize() method of the FileSystemSyncAccessHandle interface returns the size of the file associated with the + * handle in bytes. + */ + def getSize(): Double = js.native + + /** The read() method of the FileSystemSyncAccessHandle interface reads the content of the file associated with the + * handle into a specified buffer, optionally at a given offset. + * + * @param buffer + * An ArrayBuffer or ArrayBufferView (such as a DataView) representing the buffer that the file content should be + * read into. Note that you cannot directly manipulate the contents of an ArrayBuffer. Instead, you create one of + * the typed array objects like an Int8Array or a DataView object which represents the buffer in a specific format, + * and use that to read and write the contents of the buffer. + * @param options + * An options object. + * + * @return + * A number representing the number of bytes read from the file. + */ + def read(buffer: BufferSource, options: js.UndefOr[FileSystemReadWriteOptions] = js.native): Double = js.native + + /** The truncate() method of the FileSystemSyncAccessHandle interface resizes the file associated with the handle to a + * specified number of bytes. + * + * @param newSize + * The number of bytes to resize the file to. + */ + def truncate(newSize: Double): Unit = js.native + + /** The write() method of the FileSystemSyncAccessHandle interface writes the content of a specified buffer to the + * file associated with the handle, optionally at a given offset. + * + * Files within the origin private file system are not visible to end-users, therefore are not subject to the same + * security checks as methods running on files within the user-visible file system. As a result, writes performed + * using FileSystemSyncAccessHandle.write() are much more performant. This makes them suitable for significant, + * large-scale file updates such as SQLite database modifications. + * + * @param buffer + * An ArrayBuffer or ArrayBufferView (such as a DataView) representing the buffer to be written to the file. + * @param options + * An options object. + * + * @return + * A number representing the number of bytes written to the file. + */ + def write(buffer: BufferSource, options: js.UndefOr[FileSystemReadWriteOptions] = js.native): Double = js.native +} diff --git a/dom/src/main/scala/org/scalajs/dom/FileSystemWritableFileStream.scala b/dom/src/main/scala/org/scalajs/dom/FileSystemWritableFileStream.scala new file mode 100644 index 000000000..7796b79df --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/FileSystemWritableFileStream.scala @@ -0,0 +1,71 @@ +/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API + * and available under the Creative Commons Attribution-ShareAlike v2.5 or later. + * http://creativecommons.org/licenses/by-sa/2.5/ + * + * Everything else is under the MIT License http://opensource.org/licenses/MIT + */ +package org.scalajs.dom + +import scala.scalajs.js + +/** The FileSystemWritableFileStream interface of the File System API is a WritableStream object with additional + * convenience methods, which operates on a single file on disk. The interface is accessed through the + * FileSystemFileHandle.createWritable() method. + */ +@js.native +trait FileSystemWritableFileStream extends js.Object { + + /** The write() method of the FileSystemWritableFileStream interface writes content into the file the method is called + * on, at the current file cursor offset. + * + * No changes are written to the actual file on disk until the stream has been closed. Changes are typically written + * to a temporary file instead. This method can also be used to seek to a byte point within the stream and truncate + * to modify the total bytes the file contains. + * + * @param data + * Can be one of the following: + * - The file data to write, in the form of an ArrayBuffer, TypedArray, DataView, Blob, or string. + * - A WriteParams object. + * + * @return + * A Promise that returns undefined. + */ + def write(data: BufferSource): js.Promise[Unit] = js.native + + def write(data: Blob): js.Promise[Unit] = js.native + + def write(data: String): js.Promise[Unit] = js.native + + def write(data: WriteParams): js.Promise[Unit] = js.native + + /** The seek() method of the FileSystemWritableFileStream interface updates the current file cursor offset to the + * position (in bytes) specified when calling the method. + * + * @param position + * A number specifying the byte position from the beginning of the file. + * + * @return + * A Promise that returns undefined. + */ + def seek(position: Double): js.Promise[Unit] = js.native + + /** The truncate() method of the FileSystemWritableFileStream interface resizes the file associated with the stream to + * the specified size in bytes. + * + * If the size specified is larger than the current file size the file is padded with 0x00 bytes. + * + * The file cursor is also updated when truncate() is called. If the offset is smaller than the size, it remains + * unchanged. If the offset is larger than size, the offset is set to that size. This ensures that subsequent writes + * do not error. + * + * No changes are written to the actual file on disk until the stream has been closed. Changes are typically written + * to a temporary file instead. + * + * @param size + * A number specifying the number of bytes to resize the stream to. + * + * @return + * A Promise that returns undefined. + */ + def truncate(size: Double): js.Promise[Unit] = js.native +} diff --git a/dom/src/main/scala/org/scalajs/dom/StorageManager.scala b/dom/src/main/scala/org/scalajs/dom/StorageManager.scala index 2d1f2e839..e6e601238 100644 --- a/dom/src/main/scala/org/scalajs/dom/StorageManager.scala +++ b/dom/src/main/scala/org/scalajs/dom/StorageManager.scala @@ -1,3 +1,9 @@ +/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API + * and available under the Creative Commons Attribution-ShareAlike v2.5 or later. + * http://creativecommons.org/licenses/by-sa/2.5/ + * + * Everything else is under the MIT License http://opensource.org/licenses/MIT + */ package org.scalajs.dom import scala.scalajs.js @@ -7,4 +13,10 @@ trait StorageManager extends js.Object { def persisted(): js.Promise[Boolean] = js.native def persist(): js.Promise[Boolean] = js.native def estimate(): js.Promise[StorageEstimate] = js.native + + /** The getDirectory() method of the StorageManager interface is used to obtain a reference to a + * FileSystemDirectoryHandle object allowing access to a directory and its contents, stored in the origin private + * file system (OPFS). + */ + def getDirectory(): js.Promise[FileSystemDirectoryHandle] = js.native } diff --git a/dom/src/main/scala/org/scalajs/dom/WriteParams.scala b/dom/src/main/scala/org/scalajs/dom/WriteParams.scala new file mode 100644 index 000000000..e1b3e1856 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/WriteParams.scala @@ -0,0 +1,31 @@ +/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API + * and available under the Creative Commons Attribution-ShareAlike v2.5 or later. + * http://creativecommons.org/licenses/by-sa/2.5/ + * + * Everything else is under the MIT License http://opensource.org/licenses/MIT + */ +package org.scalajs.dom + +import scala.scalajs.js +import scala.scalajs.js.| + +trait WriteParams extends js.Object { + + /** A string that is one of "write", "seek", or "truncate". */ + var `type`: WriteCommandType + + /** The file data to write. Can be an ArrayBuffer, TypedArray, DataView, Blob, or string. This property is required if + * type is set to "write". + */ + var data: js.UndefOr[BufferSource | Blob | String] = js.undefined + + /** The byte position the current file cursor should move to if type "seek" is used. Can also be set if type is + * "write", in which case the write will start at the specified position. + */ + var position: js.UndefOr[Double] = js.undefined + + /** A number representing the number of bytes the stream should contain. This property is required if type is set to + * "truncate". + */ + var size: js.UndefOr[Double] = js.undefined +}