diff options
author | James M Snell <jasnell@gmail.com> | 2021-08-07 05:26:37 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-08-12 17:23:15 +0300 |
commit | 31d1d0c4c19fea5007eb8c55a4cb1178f295c8ca (patch) | |
tree | 952dace5c1d443f62208be2e1bcd5abe7dfa783e /doc/api | |
parent | 793c08b8d1b9b1f639e74bf7289acb8fb01b1765 (diff) |
url,buffer: implement URL.createObjectURL
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/39693
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Diffstat (limited to 'doc/api')
-rw-r--r-- | doc/api/buffer.md | 14 | ||||
-rw-r--r-- | doc/api/url.md | 47 |
2 files changed, 61 insertions, 0 deletions
diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 7106d5c6b36..f419be1181a 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -4952,6 +4952,20 @@ added: v3.0.0 An alias for [`buffer.constants.MAX_STRING_LENGTH`][]. +### `buffer.resolveObjectURL(id)` +<!-- YAML +added: REPLACEME +--> + +> Stability: 1 - Experimental + +* `id` {string} A `'blob:nodedata:...` URL string returned by a prior call to + `URL.createObjectURL()`. +* Returns: {Blob} + +Resolves a `'blob:nodedata:...'` an associated {Blob} object registered using +a prior call to `URL.createObjectURL()`. + ### `buffer.transcode(source, fromEnc, toEnc)` <!-- YAML added: v7.1.0 diff --git a/doc/api/url.md b/doc/api/url.md index 725084523df..d4b212f515d 100644 --- a/doc/api/url.md +++ b/doc/api/url.md @@ -608,6 +608,53 @@ console.log(JSON.stringify(myURLs)); // Prints ["https://www.example.com/","https://test.example.org/"] ``` +#### `URL.createObjectURL(blob)` +<!-- YAML +added: REPLACEME +--> + +> Stability: 1 - Experimental + +* `blob` {Blob} +* Returns: {string} + +Creates a `'blob:nodedata:...'` URL string that represents the given {Blob} +object and can be used to retrieve the `Blob` later. + +```js +const { + Blob, + resolveObjectURL, +} = require('buffer'); + +const blob = new Blob(['hello']); +const id = URL.createObjectURL(blob); + +// later... + +const otherBlob = resolveObjectURL(id); +console.log(otherBlob.size); +``` + +The data stored by the registered {Blob} will be retained in memory until +`URL.revokeObjectURL()` is called to remove it. + +`Blob` objects are registered within the current thread. If using Worker +Threads, `Blob` objects registered within one Worker will not be available +to other workers or the main thread. + +#### `URL.revokeObjectURL(id)` +<!-- YAML +added: REPLACEME +--> + +> Stability: 1 - Experimental + +* `id` {string} A `'blob:nodedata:...` URL string returned by a prior call to + `URL.createObjectURL()`. + +Removes the stored {Blob} identified by the given ID. + ### Class: `URLSearchParams` <!-- YAML added: |