-
Notifications
You must be signed in to change notification settings - Fork 161
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
[WIP] Support for OPFS #841
Draft
DanielMoss
wants to merge
1
commit into
scala-js:main
Choose a base branch
from
DanielMoss:ddm-opfs_support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
dom/src/main/scala-2/org/scalajs/dom/FileSystemHandleKind.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
} |
12 changes: 12 additions & 0 deletions
12
dom/src/main/scala-2/org/scalajs/dom/WriteCommandType.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
} |
10 changes: 10 additions & 0 deletions
10
dom/src/main/scala-3/org/scalajs/dom/FileSystemHandleKind.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
11 changes: 11 additions & 0 deletions
11
dom/src/main/scala-3/org/scalajs/dom/WriteCommandType.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
17 changes: 17 additions & 0 deletions
17
dom/src/main/scala/org/scalajs/dom/FileSystemCreateWritableOptions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
67 changes: 67 additions & 0 deletions
67
dom/src/main/scala/org/scalajs/dom/FileSystemDirectoryHandle.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
61 changes: 61 additions & 0 deletions
61
dom/src/main/scala/org/scalajs/dom/FileSystemFileHandle.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
17 changes: 17 additions & 0 deletions
17
dom/src/main/scala/org/scalajs/dom/FileSystemGetDirectoryOptions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
17 changes: 17 additions & 0 deletions
17
dom/src/main/scala/org/scalajs/dom/FileSystemGetFileOptions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
17 changes: 17 additions & 0 deletions
17
dom/src/main/scala/org/scalajs/dom/FileSystemReadWriteOptions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
15 changes: 15 additions & 0 deletions
15
dom/src/main/scala/org/scalajs/dom/FileSystemRemoveOptions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type also defines methods that return async iterators, which don't appear to be supported at the moment in scala-js. It makes sense to me to tackle those methods in a separate piece of work. I've asked about potentially adding support over in the scala-js discord.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.