mmir-tooling
Version:
Build tools for MMIR projects
134 lines (78 loc) • 3.57 kB
Markdown
**[mmir-tooling 7.0.0-beta1](../README.md)**
> [Globals](../README.md) / [mmir-lib](../modules/mmir_lib.md) / ChecksumUtils
**`example`**
var checksumUtils = require('mmirf/checksumUtils').init();
* **ChecksumUtils**
* [createContent](mmir_lib.checksumutils.md
* [getConentSeparator](mmir_lib.checksumutils.md
* [getFileExt](mmir_lib.checksumutils.md
* [init](mmir_lib.checksumutils.md
* [isSame](mmir_lib.checksumutils.md
* [parseContent](mmir_lib.checksumutils.md
▸ **createContent**(`originalText`: string, `additionalInfo?`: string): string
Creates the content for a checksum file, containing information about
the size and hash-value for the supplied String argument.
The result can be "written as is" to a file.
Name | Type | Description |
------ | ------ | ------ |
`originalText` | string | the "raw" text for which to generate the checksum information |
`additionalInfo?` | string | - |
**Returns:** string
the checksum information as a String (formatted as content of a checksum file)
___
### getConentSeparator
▸ **getConentSeparator**(): string
The Char used for separating fields within checksum files.
**Returns:** string
the separator char (TAB)
___
### getFileExt
▸ **getFileExt**(): string
Returns the file extension for checksum-files.
**Returns:** string
the default file extension for checksum files
(including the separating dot, eg. ".checksum.txt")
___
### init
▸ **init**(`cryptoImpl?`: [CryptoImpl](../modules/mmir_lib.md#cryptoimpl)): void
Must be called before using checksum-generation:
sets/initializes the object/function for checksum generation.
After first call, following calls to this function will have no effect.
#### Parameters:
Name | Type |
------ | ------ |
`cryptoImpl?` | [CryptoImpl](../modules/mmir_lib.md#cryptoimpl) |
**Returns:** void
___
### isSame
▸ **isSame**(`rawTextContent`: string, `referenceHash`: string \| [ChecksumInfo](../modules/mmir_lib.md#checksuminfo), `additionalInfo?`: string): boolean
Check if the length / checksum for a raw text is the same as the checksum-information.
NOTE: The actual checksum for the raw text is only generated & checked, if the size is equal.
**`function`**
#### Parameters:
Name | Type | Description |
------ | ------ | ------ |
`rawTextContent` | string | the (raw) text/content which should be checked |
`referenceHash` | string \| [ChecksumInfo](../modules/mmir_lib.md#checksuminfo) | the checksum information to check against: either the raw content (String) of a checksum file, or the parsed contents of a checksum file, which is a PlainObject with properties: <pre>{ size: INTEGER, hash: STRING, info?: STRING }</pre> |
`additionalInfo?` | string | - |
**Returns:** boolean
<code>true</code> if the raw content matches the hash
___
▸ **parseContent**(`rawTextContent`: string): [ChecksumInfo](../modules/mmir_lib.md
Parses the raw text-content of a checksum file and returns an object
with properties:
Name | Type | Description |
------ | ------ | ------ |
`rawTextContent` | string | the raw conent of a checksum file |
**Returns:** [ChecksumInfo](../modules/mmir_lib.md
an object with the extracted properties from the checksum-data:
<pre>{ size: INTEGER, hash: STRING, info?: STRING }</pre>