Interface ProgressResolver

Hierarchy

  • ProgressResolver

Properties

Properties

progress: (<T, C, R>(this, onProgress) => ProgressResolver)

Type declaration

    • <T, C, R>(this, onProgress): ProgressResolver
    • Provides a way to register a callback to be invoked one or multiple times during the download. The callback receives the current progress as two arguments, the number of bytes loaded and the total number of bytes to load.

      Under the hood: this method adds a middleware to the chain that will intercept the response and replace the body with a new one that will emit the progress event.

      import ProgressAddon from "wretch/addons/progress"

      wretch("some_url")
      // Register the addon
      .addon(ProgressAddon())
      .get()
      // Log the progress as a percentage of completion
      .progress((loaded, total) => console.log(`${(loaded / total * 100).toFixed(0)}%`))

      Type Parameters

      Parameters

      • this: C & WretchResponseChain<T, C, R>
      • onProgress: ((loaded, total) => void)

        A callback that will be called one or multiple times with the number of bytes loaded and the total number of bytes to load.

          • (loaded, total): void
          • Parameters

            • loaded: number
            • total: number

            Returns void

      Returns ProgressResolver

Generated using TypeDoc