Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.d.ts 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /// <reference types="node"/>
  2. import {LiteralUnion} from 'type-fest';
  3. import {Hash} from 'crypto';
  4. declare namespace hasha {
  5. type ToStringEncoding = 'hex' | 'base64' | 'latin1';
  6. type HashaInput = Buffer | string | Array<Buffer | string>;
  7. type HashaEncoding = ToStringEncoding | 'buffer';
  8. type AlgorithmName = LiteralUnion<
  9. 'md5' | 'sha1' | 'sha256' | 'sha512',
  10. string
  11. >;
  12. interface Options<EncodingType = HashaEncoding> {
  13. /**
  14. Encoding of the returned hash.
  15. @default 'hex'
  16. */
  17. readonly encoding?: EncodingType;
  18. /**
  19. Values: `md5` `sha1` `sha256` `sha512` _([Platform dependent](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options))_
  20. _The `md5` algorithm is good for [file revving](https://github.com/sindresorhus/rev-hash), but you should never use `md5` or `sha1` for anything sensitive. [They're insecure.](https://security.googleblog.com/2014/09/gradually-sunsetting-sha-1.html)_
  21. @default 'sha512'
  22. */
  23. readonly algorithm?: AlgorithmName;
  24. }
  25. }
  26. declare const hasha: {
  27. /**
  28. Calculate the hash for a `string`, `Buffer`, or an array thereof.
  29. @param input - Data you want to hash.
  30. While strings are supported you should prefer buffers as they're faster to hash. Although if you already have a string you should not convert it to a buffer.
  31. Pass an array instead of concatenating strings and/or buffers. The output is the same, but arrays do not incur the overhead of concatenation.
  32. @returns A hash.
  33. @example
  34. ```
  35. import hasha = require('hasha');
  36. hasha('unicorn');
  37. //=> 'e233b19aabc7d5e53826fb734d1222f1f0444c3a3fc67ff4af370a66e7cadd2cb24009f1bc86f0bed12ca5fcb226145ad10fc5f650f6ef0959f8aadc5a594b27'
  38. ```
  39. */
  40. (input: hasha.HashaInput): string;
  41. (
  42. input: hasha.HashaInput,
  43. options: hasha.Options<hasha.ToStringEncoding>
  44. ): string;
  45. (input: hasha.HashaInput, options: hasha.Options<'buffer'>): Buffer;
  46. /**
  47. Asynchronously calculate the hash for a `string`, `Buffer`, or an array thereof.
  48. In Node.js 12 or later, the operation is executed using `worker_threads`. A thread is lazily spawned on the first operation and lives until the end of the program execution. It's unrefed, so it won't keep the process alive.
  49. @param input - Data you want to hash.
  50. While strings are supported you should prefer buffers as they're faster to hash. Although if you already have a string you should not convert it to a buffer.
  51. Pass an array instead of concatenating strings and/or buffers. The output is the same, but arrays do not incur the overhead of concatenation.
  52. @returns A hash.
  53. @example
  54. ```
  55. import hasha = require('hasha');
  56. (async () => {
  57. console.log(await hasha.async('unicorn'));
  58. //=> 'e233b19aabc7d5e53826fb734d1222f1f0444c3a3fc67ff4af370a66e7cadd2cb24009f1bc86f0bed12ca5fcb226145ad10fc5f650f6ef0959f8aadc5a594b27'
  59. })();
  60. ```
  61. */
  62. async(input: hasha.HashaInput): Promise<string>;
  63. async(
  64. input: hasha.HashaInput,
  65. options: hasha.Options<hasha.ToStringEncoding>
  66. ): Promise<string>;
  67. async(input: hasha.HashaInput, options: hasha.Options<'buffer'>): Promise<Buffer>;
  68. /**
  69. Create a [hash transform stream](https://nodejs.org/api/crypto.html#crypto_class_hash).
  70. @returns The created hash transform stream.
  71. @example
  72. ```
  73. import hasha = require('hasha');
  74. // Hash the process input and output the hash sum
  75. process.stdin.pipe(hasha.stream()).pipe(process.stdout);
  76. ```
  77. */
  78. stream(options?: hasha.Options<hasha.HashaEncoding>): Hash;
  79. /**
  80. Calculate the hash for a stream.
  81. @param stream - A stream you want to hash.
  82. @returns The calculated hash.
  83. */
  84. fromStream(stream: NodeJS.ReadableStream): Promise<string>;
  85. fromStream(
  86. stream: NodeJS.ReadableStream,
  87. options?: hasha.Options<hasha.ToStringEncoding>
  88. ): Promise<string>;
  89. fromStream(
  90. stream: NodeJS.ReadableStream,
  91. options?: hasha.Options<'buffer'>
  92. ): Promise<Buffer>;
  93. /**
  94. Calculate the hash for a file.
  95. In Node.js 12 or later, the operation is executed using `worker_threads`. A thread is lazily spawned on the first operation and lives until the end of the program execution. It's unrefed, so it won't keep the process alive.
  96. @param filePath - Path to a file you want to hash.
  97. @returns The calculated file hash.
  98. @example
  99. ```
  100. import hasha = require('hasha');
  101. (async () => {
  102. // Get the MD5 hash of an image
  103. const hash = await hasha.fromFile('unicorn.png', {algorithm: 'md5'});
  104. console.log(hash);
  105. //=> '1abcb33beeb811dca15f0ac3e47b88d9'
  106. })();
  107. ```
  108. */
  109. fromFile(filePath: string): Promise<string>;
  110. fromFile(
  111. filePath: string,
  112. options: hasha.Options<hasha.ToStringEncoding>
  113. ): Promise<string>;
  114. fromFile(
  115. filePath: string,
  116. options: hasha.Options<'buffer'>
  117. ): Promise<Buffer>;
  118. /**
  119. Synchronously calculate the hash for a file.
  120. @param filePath - Path to a file you want to hash.
  121. @returns The calculated file hash.
  122. */
  123. fromFileSync(filePath: string): string;
  124. fromFileSync(
  125. filePath: string,
  126. options: hasha.Options<hasha.ToStringEncoding>
  127. ): string;
  128. fromFileSync(filePath: string, options: hasha.Options<'buffer'>): Buffer;
  129. };
  130. export = hasha;