Skip to content
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

Chrome Apps and FileWriter are deprecated: Substitute File System Access API for FileWriter #34

Open
guest271314 opened this issue Aug 1, 2021 · 1 comment

Comments

@guest271314
Copy link
Contributor

Chrome apps are deprecated, see https://developer.chrome.com/docs/extensions/reference/fileSystem/

This API is part of the deprecated Chrome Apps platform. Learn more about migrating your app.

Following the "migrating your app link" to chrome.fileSystem

chrome.fileSystemNative FileSystem API

and #31.

To substitute WritableStreamDefaultWriter for FileWriter in webm-writer-js at

if (destination && destination.constructor.name === "FileWriter") {

if (
        typeof FileSystemFileHandle !== 'undefined' &&
        destination instanceof WritableStreamDefaultWriter
      )

and

} else if (fileWriter) {
return new Promise(function (resolve, reject) {
fileWriter.onwriteend = resolve;
fileWriter.seek(newEntry.offset);
fileWriter.write(new Blob([newEntry.data]));
});
} else if (!isAppend) {

          } else if (fileWriter) {
            return new Promise(async function (resolve, reject) {
              // fileWriter.onwriteend = resolve;
              if (newEntry.offset === 0) {
                await fileWriter.ready;
              }
              console.log(newEntry.offset);
              // await fileWriter.seek(newEntry.offset)
              await fileWriter.write({
                type: 'write',
                position: newEntry.offset,
                data: new Blob([newEntry.data]),
              });
              resolve();
            });
          }

Usage

document.querySelector('p').onclick = async () => {
  fileHandle = await showSaveFilePicker({
    suggestedName: 'webm-writer-filesystem-access.webm',
    startIn: 'videos',
    id: 'webm-writer',
    types: [
      {
        description: 'WebM files',
        accept: {
          'video/webm': ['.webm'],
        },
      },
    ],
    excludeAcceptAllOption: true,
  });
  writable = await fileHandle.createWritable();
  fileWriter = await writable.getWriter();
  videoWriter = new WebMWriter({
    quality: 0.95, // WebM image quality from 0.0 (worst) to 1.0 (best)
    fileWriter, // FileWriter in order to stream to a file instead of buffering to memory (optional)
    fd: null, // Node.js file handle to write to instead of buffering to memory (optional)
    // You must supply one of:
    frameDuration: null, // Duration of frames in milliseconds
    frameRate: 30, // Number of frames per second
    // add support for variable resolution, variable frame duration, data URL representation of WebP input
    variableResolution: true, // frameRate is not used for variable resolution
  });
};

Test
webm-writer-js-file-system-access.zip

@guest271314
Copy link
Contributor Author

WHATWG File System is now implemented in Chromium (Chrome), Firefox, Safari, which unlike WICG File System Access which writes directly to user-selected directories and files, writes File objects to the origin private filesystem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant