MCPcopy Create free account
hub / github.com/cryptii/cryptii / performEncode

Method performEncode

src/Encoder/CharacterBlock.js:76–93  ·  view source on GitHub ↗

* Performs encode on given content. * @protected * @param {Chain} content * @return {number[]|string|Uint8Array|Chain|Promise} Encoded content

(content)

Source from the content-addressed store, hash-verified

74 * @return {number[]|string|Uint8Array|Chain|Promise} Encoded content
75 */
76 performEncode (content) {
77 switch (this._mode) {
78 case CharacterToBlockMode: {
79 const blocks = content.getCodePoints()
80 .map((codePoint, index) =>
81 this.performCharEncodeToBlock(codePoint, index, content))
82 .filter(block => block !== null)
83 .map(Chain.wrap)
84 return Chain.join(blocks, this.getSeparator())
85 }
86 case BlockToCharacterMode: {
87 return content.split(this.getSeparator())
88 .map((block, index, blocks) =>
89 this.performBlockEncodeToChar(block, index, blocks, content))
90 .filter(codePoint => codePoint !== null)
91 }
92 }
93 }
94
95 /**
96 * Performs decode on given content.

Callers

nothing calls this directly

Calls 6

getSeparatorMethod · 0.95
getCodePointsMethod · 0.80
joinMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected