happy-opfs
    Preparing search index...

    Function attach

    • Attaches to an existing SharedArrayBuffer for synchronous file system operations. Used to share a sync channel connection with other contexts (e.g., iframes).

      After calling this function, sync APIs (e.g., readFileSync, writeFileSync) can be used in the current context without calling connect.

      Parameters

      • sharedBuffer: SharedArrayBuffer

        The SharedArrayBuffer received from another context.

      • Optionaloptions: AttachSyncChannelOptions

        Optional configuration options.

      Returns VoidIOResult

      A VoidIOResult indicating success or failure.

      1.8.5

      // In iframe: receive SharedArrayBuffer from main page
      window.addEventListener('message', (event) => {
      if (event.data.sharedBuffer) {
      const result = SyncChannel.attach(event.data.sharedBuffer, { opTimeout: 5000 });
      if (result.isOk()) {
      // Now sync APIs can be used
      const fileResult = readTextFileSync('/data/file.txt');
      }
      }
      });