recursal/MDN huggingface dataset:
WritableStreamDefaultWriter: ready property
===========================================

 The **`ready`** read-only property of the
 `WritableStreamDefaultWriter` interface returns a `Promise`
 that resolves when the desired size of the stream's internal queue transitions from
 non-positive to positive, signaling that it is no longer applying backpressure.

Value
-----

A `Promise`.

Examples
--------

 The following example shows two uses of the `ready` property. The first uses
 `ready` to ensure that the `WritableStream` is done writing and
 thus able to receive data before sending a binary chunk. The second also checks whether
 the `WritableStream` is done writing, but this time because the writing
 must be finished before the writer can be closed.


```js
function sendMessage(message, writableStream) {
  // defaultWriter is of type WritableStreamDefaultWriter
  const defaultWriter = writableStream.getWriter();
  const encoder = new TextEncoder();
  const encoded = encoder.encode(message);
  encoded.forEach((chunk) => {
    // Make sure the stream and its writer are able to
    // receive data.
    defaultWriter.ready
      .then(() => defaultWriter.write(chunk))
      .then(() => {
        console.log("Chunk written to sink.");
      })
      .catch((err) => {
        console.error(`Chunk error: ${err}`);
      });
    // Call ready again to ensure that all chunks are written
    // before closing the writer.
    defaultWriter.ready
      .then(() => defaultWriter.close())
      .then(() => {
        console.log("All chunks written");
      })
      .catch((err) => {
        console.error(`Stream error: ${err}`);
      });
  });
}
```

Specifications
--------------

| Specification |
| --- |
| Streams Standard # ref-for-default-writer-ready⑨ |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
WritableStreamDefaultWriter: abort() method
===========================================

 The **`abort()`** method of the
 `WritableStreamDefaultWriter` interface aborts the stream, signaling that
 the producer can no longer successfully write to the stream and it is to be immediately
 moved to an error state, with any queued writes discarded.

 If the writer is active, the `abort()` method behaves the same as that for
 the associated stream (`WritableStream.abort()`). If not, it returns a
 rejected promise.

Syntax
------


```js
abort()
abort(reason)
```

### Parameters

`reason` Optional

A string representing a human-readable reason for the abort.

### Return value

 A `Promise`, which fulfills to `undefined` when the stream is aborted, or
 rejects with an error if the writer was inactive or the receiver stream is invalid.

### Exceptions

`TypeError`

 The stream you are trying to abort is not a `WritableStream`, or it is
 locked.


Examples
--------


```js
const writableStream = new WritableStream(
  {
    write(chunk) {
      // ...
    },
    close() {
      // ...
    },
    abort(err) {
      // ...
    },
  },
  queuingStrategy,
);

// ...

const writer = writableStream.getWriter();

// ...

// abort the stream when desired
await writer.abort("WritableStream aborted. Reason: ...");
```

Specifications
--------------

| Specification |
| --- |
| Streams Standard # ref-for-default-writer-abort④ |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
WritableStreamDefaultWriter: closed property
============================================

 The **`closed`** read-only property of the
 `WritableStreamDefaultWriter` interface returns a
 `Promise` that fulfills if the stream becomes closed, or rejects if
 the stream errors or the writer's lock is released.

Value
-----

A `Promise`.

Examples
--------


```js
const writableStream = new WritableStream(
  {
    start(controller) {},
    write(chunk, controller) {
      // ...
    },
    close(controller) {
      // ...
    },
    abort(err) {
      // ...
    },
  },
  queuingStrategy,
);

// ...

const writer = writableStream.getWriter();

// ..

// check if the stream is closed
writer.closed.then(() => {
  console.log("writer closed");
});
```

Specifications
--------------

| Specification |
| --- |
| Streams Standard # ref-for-default-writer-closed② |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
FileSystemEntry: isFile property
================================

 The read-only **`isFile`** property of
 the `FileSystemEntry` interface is `true` if the entry
 represents a file (meaning it's a `FileSystemFileEntry`) and
 `false` if it's not.

 You can also use `isDirectory` to determine
 if the entry is a directory.


**Warning:** You should not assume that any entry which isn't a file is a directory or vice versa.
 There are other types of file descriptors on many operating systems. Be sure to use
 both `isDirectory` and `isFile` as needed to ensure that the
 entry is something you know how to work with.


Value
-----

A Boolean indicating whether or not the `FileSystemEntry` is a file.

Examples
--------

 This example shows how this property might be used to determine whether to process the
 entry as a directory or file. If the entry is neither, an error handler is called with
 an appropriate message.


```js
if (entry.isDirectory) {
  processSubdirectory(entry);
} else if (entry.isFile) {
  processFile(entry);
} else {
  displayErrorMessage("Unsupported file system entry specified.");
}
```

Specifications
--------------

| Specification |
| --- |
| File and Directory Entries API # dom-filesystementry-isfile |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* File and Directory Entries API
* Introduction to the File and Directory Entries API
* `FileSystemEntry`
* `FileSystemEntry.isDirectory`
* `FileSystemFileEntry`
FileSystemEntry: remove() method
================================

**Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

**Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

 The `FileSystemEntry` interface's method
 **`remove()`** deletes the file
 or directory from the file system. Directories must be empty before they can be
 removed.

 To recursively remove a directory as well as all of its contents and its
 subdirectories, call `FileSystemDirectoryEntry.removeRecursively()`
 instead.

Syntax
------


```js
remove(successCallback)
remove(successCallback, errorCallback)
```

### Parameters

`successCallback`

A function which is called once the file has been successfully removed.

`errorCallback` Optional

An optional callback which is called if the attempt to remove the file fails.

### Return value

None (`undefined`).

### Errors

`FileError.INVALID_MODIFICATION_ERR`

 The specified entry was the file system's root directory, or the specified entry is
 a directory which isn't empty.


`FileError.INVALID_STATE_ERR`

 The file system's cached state is inconsistent with its state on disk, so the file
 could not be deleted for safety reasons.


`FileError.NO_MODIFICATION_ALLOWED_ERR`

The file system's state doesn't permit removing the file or directory.

`FileError.NOT_FOUND_ERR`

The file or directory doesn't exist.

`FileError.SECURITY_ERR`

 The entry couldn't be removed due to permissions or other access constraints, or
 because there are too many calls being made on file resources.


Examples
--------

This example deletes a temporary work file.


```js
workingDirectory.getFile(
  "tmp/workfile.json",
  {},
  (fileEntry) => {
    fileEntry.remove(() => {
      /\* the file was removed successfully \*/
    });
  },
  handleError,
);
```

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* File and Directory Entries API
* Introduction to the File and Directory Entries API
* `FileSystemDirectoryEntry.removeRecursively()`
FileSystemEntry: getParent() method
===================================

 The `FileSystemEntry` interface's method
 **`getParent()`** obtains a
 `FileSystemDirectoryEntry`.

Syntax
------


```js
getParent(successCallback, errorCallback)
getParent(successCallback)
```

### Parameters

`successCallback`

 A function which is called when the parent directory entry has been retrieved. The
 callback receives a single input parameter: a `FileSystemDirectoryEntry`
 object representing the parent directory. The parent of the root directory is
 considered to be the root directory, itself, so be sure to watch for that.


`errorCallback` Optional

 An optional callback which is executed if an error occurs. There's a single
 parameter: a `DOMException` describing what went wrong.


### Return value

None (`undefined`).

### Errors

`FileError.INVALID_STATE_ERR`

 The operation failed because the file system's state doesn't permit it. This can
 happen, for example, if the file system's cached state differs from the actual state
 of the file system.


`FileError.NOT_FOUND_ERR`

The specified path could not be found.

`FileError.SECURITY_ERR`

Security restrictions prohibit obtaining the parent directory's information.

Examples
--------

 This example renames the file specified by the variable `fileEntry` to
 `"newname.html"`.


```js
fileEntry.getParent(
  (parent) => {
    fileEntry.moveTo(parent, "newname.html", (updatedEntry) => {
      console.log(`File ${fileEntry.name} renamed to newname.html.`);
    });
  },
  (error) => {
    console.error(
      `An error occurred: Unable to rename ${fileEntry.name} to newname.html.`,
    );
  },
);
```


 This is accomplished by first obtaining a `FileSystemDirectoryEntry`
 object representing the directory the file is currently located in. Then
 `moveTo()` is used to rename the file within that
 directory.

Using promises
--------------

 Currently, there isn't a `Promise`-based version of this method. You can,
 however, create a simple helper function to adapt it, like this:


```js
function getParentPromise(entry) {
  return new Promise((resolve, reject) => {
    entry.getParent(resolve, reject);
  });
}
```


A similar approach can be taken elsewhere in the File and Directory Entries API.

Specifications
--------------

| Specification |
| --- |
| File and Directory Entries API # dom-filesystementry-getparent |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* File and Directory Entries API
* Introduction to the File and Directory Entries API
FileSystemEntry: isDirectory property
=====================================

 The read-only **`isDirectory`**
 property of the `FileSystemEntry` interface is `true` if the
 entry represents a directory (meaning it's a `FileSystemDirectoryEntry`)
 and `false` if it's not.

 You can also use `isFile` to determine if the
 entry is a file.


**Warning:** You should not assume that any entry which isn't a directory is a file or vice versa.
 There are other types of file descriptors on many operating systems. Be sure to use
 both `isDirectory` and `isFile` as needed to ensure that the
 entry is something you know how to work with.


Value
-----

A Boolean indicating whether or not the `FileSystemEntry` is a directory.

Examples
--------

 This example shows how this property might be used to determine whether to process the
 entry as a directory or file. If the entry is neither, an error handler is called with
 an appropriate message.


```js
if (entry.isDirectory) {
  processSubdirectory(entry);
} else if (entry.isFile) {
  processFile(entry);
} else {
  displayErrorMessage("Unsupported file system entry specified.");
}
```

Specifications
--------------

| Specification |
| --- |
| File and Directory Entries API # dom-filesystementry-isdirectory |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* File and Directory Entries API
* Introduction to the File and Directory Entries API
* `FileSystemEntry`
* `FileSystemEntry.isFile`
* `FileSystemDirectoryEntry`
FileSystemEntry: getMetadata() method
=====================================

**Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

**Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

 The `FileSystemEntry` interface's method
 **`getMetadata()`** obtains a
 `Metadata` object with information about the file system entry, such as
 its modification date and time and its size.

Syntax
------


```js
getMetadata(successCallback)
getMetadata(successCallback, errorCallback)
```

### Parameters

`successCallback`

 A function which is called when the copy operation is successfully completed.
 Receives a single input parameter: a `Metadata` object with information
 about the file.


`errorCallback` Optional

 An optional callback which is executed if an error occurs while looking up the
 metadata. There's a single parameter: a `FileError` describing what went
 wrong.


### Return value

None (`undefined`).

### Errors

`FileError.NOT_FOUND_ERR`

The `FileSystemEntry` refers to an item which doesn't exist.

`FileError.SECURITY_ERR`

Security restrictions prohibit obtaining the requested metadata.

Examples
--------

 This example checks the size of a log file in a temporary folder and, if it exceeds a
 megabyte, moves it into a different directory.


```js
workingDirectory.getFile(
  "tmp/log.txt",
  {},
  (fileEntry) => {
    fileEntry.getMetadata((metadata) => {
      if (metadata.size > 1048576) {
        workingDirectory.getDirectory(
          "log",
          {},
          (dirEntry) => {
            fileEntry.moveTo(dirEntry);
          },
          handleError,
        );
      }
    });
  },
  handleError,
);
```

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* File and Directory Entries API
* Introduction to the File and Directory Entries API
FileSystemEntry: name property
==============================

 The read-only **`name`** property of
 the `FileSystemEntry` interface returns a string
 specifying the entry's name; this is the entry within its parent directory (the last
 component of the path as indicated by the `fullPath` property).

Value
-----

A string indicating the entry's name.

Examples
--------

 This example shows a function called `isFileWithExtension()` which returns
 true if the specified `FileSystemEntry` is both a file and the file's name
 ends with a given extension.


```js
function isFileWithExtension(entry, extension) {
  return entry.isFile && entry.name.endsWith(`.${extension}`);
}
```

Specifications
--------------

| Specification |
| --- |
| File and Directory Entries API # dom-filesystementry-name |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* File and Directory Entries API
* Introduction to the File and Directory Entries API
* `FileSystemEntry`
* `FileSystemEntry.fullPath`
FileSystemEntry: toURL() method
===============================

**Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

**Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

 The `FileSystemEntry` interface's method
 **`toURL()`** creates and
 returns a string containing a URL which can be used to identify the file system entry.
 This is done by exposing a new URL scheme—`filesystem:`—that can be used as
 the value of `src` and `href` attributes.

Syntax
------


```js
toURL()
toURL(mimeType)
```

### Parameters

`mimeType` Optional

 An optional string specifying the MIME type to use when interpreting the file. This
 can be used to help deal with files whose types aren't recognized automatically by the
 user agent. If this parameter is omitted, the user agent uses its standard algorithms
 to identify the file.


### Return value

 A string containing a URL that can then be used as a document
 reference in HTML content, or an empty string if the URL can't be generated (such as if
 the file system implementation doesn't support `toURL()`).

Examples
--------

 If you have a `FileSystemFileEntry` corresponding to an image file in a
 file system available to your website or app, you can call `toURL()` to get
 its URL for use in HTML. If your site is located at
 `http://my-awesome-website.woot`, and you have a temporary file system that
 contains an image file named `awesomesauce.jpg`, the URL returned by
 `toURL()` might be (depending on the browser's implementation) something like
 `"filesystem:http://my-awesome-website.woot/temporary/awesomesauce.jpg"`.

Code that makes use of this might look like this:


```js
let img = document.createElement("img");

img.src = imageFileEntry.toURL();
document.body.appendChild(img);
```


 Assuming the scenario mentioned before the code, the result would be HTML that looks
 like this being appended to the end of the document:


```html
<img
 src="filesystem:http://my-awesome-website.woot/temporary/awesomesauce.jpg" />
```

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* File and Directory Entries API
* Introduction to the File and Directory Entries API
* `FileSystemDirectoryEntry.removeRecursively()`
FileSystemEntry: filesystem property
====================================

 The read-only **`filesystem`**
 property of the `FileSystemEntry` interface contains a
 `FileSystem` object that represents the file system on which the entry
 resides.

Value
-----

 A `FileSystem` representing the file system on which the file or directory
 described by the `FileSystemEntry` is located.

Examples
--------

 This example obtains a `FileSystemDirectoryEntry` for the root directory
 of the file system containing a file.


```js
let rootDirEntry = fileEntry.filesystem.root;
```

Specifications
--------------

| Specification |
| --- |
| File and Directory Entries API # dom-filesystementry-filesystem |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* File and Directory Entries API
* Introduction to the File and Directory Entries API
* `FileSystemEntry`
* `FileSystem`
FileSystemEntry: copyTo() method
================================

**Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

**Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

 The `FileSystemEntry` interface's method
 **`copyTo()`** copies the file
 specified by the entry to a new location on the file system.

 There are some
 typical restrictions on what you can do:

* A directory can't be copied into itself.
* An entry can't be copied into its parent directory unless you specify a new name.
* When copying a directory, the copy is always recursive; you can't leave out
 subfolders.
Syntax
------


```js
copyTo(newParent)
copyTo(newParent, newName)
copyTo(newParent, newName, successCallback)
copyTo(newParent, newName, successCallback, errorCallback)
```

### Parameters

`newParent`

 A `FileSystemDirectoryEntry` object specifying the destination
 directory for the copy operation.


`newName` Optional

 If this parameter is provided, the copy is given this string as its new file or
 directory name.


`successCallback` Optional

 A function which is called when the copy operation is successfully completed.
 Receives a single input parameter: a `FileSystemEntry` based object
 providing the copied item's new details.


`errorCallback` Optional

 An optional callback which is executed if an error occurs while copying the items.
 There's a single parameter: a `FileError` describing what went wrong.


### Return value

None (`undefined`).

### Errors

`FileError.INVALID_MODIFICATION_ERR`

 The requested operation involves an impossible change, such as moving a directory
 inside itself or one of its own child directories, or copying an item within the same
 directory without renaming it.


`FileError.QUOTA_EXCEEDED_ERR`

 The operation exceeded the user's storage quota, or there isn't enough storage space
 left to complete the operation.


Examples
--------

 This example shows how a temporary log file might be moved into a more permanent "log"
 directory.


```js
workingDirectory.getFile(
  "tmp/log.txt",
  {},
  (fileEntry) => {
    workingDirectory.getDirectory(
      "log",
      {},
      (dirEntry) => {
        fileEntry.copyTo(dirEntry);
      },
      handleError,
    );
  },
  handleError,
);
```

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* File and Directory Entries API
* Introduction to the File and Directory Entries API