index.d.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. /// <reference types="node" />
  2. import { Readable } from 'stream';
  3. import { UrlWithStringQuery } from 'url';
  4. /**
  5. * Async function that returns a `stream.Readable` instance to the
  6. * callback function that will output the contents of the given URI.
  7. *
  8. * For caching purposes, you can pass in a `stream` instance from a previous
  9. * `getUri()` call as a `cache: stream` option, and if the destination has
  10. * not changed since the last time the endpoint was retreived then the callback
  11. * will be invoked with an Error object with `code` set to "ENOTMODIFIED" and
  12. * `null` for the "stream" instance argument. In this case, you can skip
  13. * retreiving the file again and continue to use the previous payload.
  14. *
  15. * @param {String} uri URI to retrieve
  16. * @param {Object} opts optional "options" object
  17. * @param {Function} fn callback function
  18. * @api public
  19. */
  20. declare function getUri(uri: string, fn: getUri.GetUriCallback): void;
  21. declare function getUri(uri: string, opts: getUri.GetUriOptions, fn: getUri.GetUriCallback): void;
  22. declare function getUri(uri: string, opts?: getUri.GetUriOptions): Promise<Readable>;
  23. declare namespace getUri {
  24. interface GetUriOptions {
  25. cache?: Readable;
  26. }
  27. type GetUriCallback = (err?: Error | null, res?: Readable) => void;
  28. type GetUriProtocol = (parsed: UrlWithStringQuery, opts: getUri.GetUriOptions) => Promise<Readable>;
  29. const protocols: {
  30. [key: string]: getUri.GetUriProtocol;
  31. };
  32. }
  33. export = getUri;