index.d.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /// <reference types="node"/>
  2. import * as stream from 'stream';
  3. import {ZlibOptions} from 'zlib';
  4. declare namespace gzipSize {
  5. type Options = ZlibOptions;
  6. interface GzipSizeStream extends stream.PassThrough {
  7. addListener(event: 'gzip-size', listener: (size: number) => void): this;
  8. addListener(
  9. event: string | symbol,
  10. listener: (...args: any[]) => void
  11. ): this;
  12. on(event: 'gzip-size', listener: (size: number) => void): this;
  13. on(event: string | symbol, listener: (...args: any[]) => void): this;
  14. once(event: 'gzip-size', listener: (size: number) => void): this;
  15. once(event: string | symbol, listener: (...args: any[]) => void): this;
  16. removeListener(event: 'gzip-size', listener: (size: number) => void): this;
  17. removeListener(
  18. event: string | symbol,
  19. listener: (...args: any[]) => void
  20. ): this;
  21. off(event: 'gzip-size', listener: (size: number) => void): this;
  22. off(event: string | symbol, listener: (...args: any[]) => void): this;
  23. emit(event: 'gzip-size', size: number): boolean;
  24. emit(event: string | symbol, ...args: any[]): boolean;
  25. prependListener(event: 'gzip-size', listener: (size: number) => void): this;
  26. prependListener(
  27. event: string | symbol,
  28. listener: (...args: any[]) => void
  29. ): this;
  30. prependOnceListener(
  31. event: 'gzip-size',
  32. listener: (size: number) => void
  33. ): this;
  34. prependOnceListener(
  35. event: string | symbol,
  36. listener: (...args: any[]) => void
  37. ): this;
  38. /**
  39. Contains the gzip size of the stream after it is finished. Since this happens asynchronously, it is recommended you use the `gzip-size` event instead.
  40. */
  41. gzipSize?: number;
  42. }
  43. }
  44. declare const gzipSize: {
  45. /**
  46. Get the gzipped size of a string or buffer.
  47. @returns The gzipped size of `input`.
  48. */
  49. (input: string | Buffer, options?: gzipSize.Options): Promise<number>;
  50. /**
  51. Synchronously get the gzipped size of a string or buffer.
  52. @returns The gzipped size of `input`.
  53. @example
  54. ```
  55. import gzipSize = require('gzip-size');
  56. const text = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.';
  57. console.log(text.length);
  58. //=> 191
  59. console.log(gzipSize.sync(text));
  60. //=> 78
  61. ```
  62. */
  63. sync(input: string | Buffer, options?: gzipSize.Options): number;
  64. /**
  65. @returns A stream that emits a `gzip-size` event and has a `gzipSize` property.
  66. */
  67. stream(options?: gzipSize.Options): gzipSize.GzipSizeStream;
  68. /**
  69. Get the gzipped size of a file.
  70. @returns The size of the file.
  71. */
  72. file(path: string, options?: gzipSize.Options): Promise<number>;
  73. /**
  74. Synchronously get the gzipped size of a file.
  75. @returns The size of the file.
  76. */
  77. fileSync(path: string, options?: gzipSize.Options): number;
  78. };
  79. export = gzipSize;