mwg API
    Preparing search index...

    Function fetchWithByteProgress

    • Fetches url, reporting real bytes transferred as they arrive, and resolves to the complete body as a Blob - handed to URL.createObjectURL to become something assets.load's own texture/audio/JSON decoding can take from there, the same as any other resolved asset URL.

      Parameters

      • url: string
      • OptionalonProgress: OnByteProgress
      • fetchFn: {
            (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
            (input: string | URL | Request, init?: RequestInit): Promise<Response>;
        } = fetch
          • (input: URL | RequestInfo, init?: RequestInit): Promise<Response>
          • Parameters

            • input: URL | RequestInfo
            • Optionalinit: RequestInit

            Returns Promise<Response>

          • (input: string | URL | Request, init?: RequestInit): Promise<Response>
          • Parameters

            • input: string | URL | Request
            • Optionalinit: RequestInit

            Returns Promise<Response>

      Returns Promise<Blob>

      import { fetchWithByteProgress } from '@datamoc/mw_games/assets';

      const blob = await fetchWithByteProgress('https://example.com/big-tileset.png', (progress) => {
      if (progress.total) console.log(`${progress.loaded} / ${progress.total} bytes`);
      });
      const url = URL.createObjectURL(blob);