base64.html 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <!-- This file is generated by Nim. -->
  4. <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>std/base64</title>
  9. <!-- Google fonts -->
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
  11. <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
  12. <!-- Favicon -->
  13. <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
  14. <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
  15. <!-- CSS -->
  16. <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
  17. <!-- JS -->
  18. <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
  19. </head>
  20. <body>
  21. <div class="document" id="documentId">
  22. <div class="container">
  23. <h1 class="title">std/base64</h1>
  24. <div class="row">
  25. <div class="three columns">
  26. <div class="theme-select-wrapper">
  27. <label for="theme-select">Theme:&nbsp;</label>
  28. <select id="theme-select" onchange="setTheme(this.value)">
  29. <option value="auto">🌗 Match OS</option>
  30. <option value="dark">🌑 Dark</option>
  31. <option value="light">🌕 Light</option>
  32. </select>
  33. </div>
  34. <div id="global-links">
  35. <ul class="simple-boot">
  36. <li><a href="manual.html">Manual</a></li>
  37. <li><a href="lib.html">Standard library</a></li>
  38. <li> <a id="indexLink" href="theindex.html">Index</a></li>
  39. <li><a href="compiler/theindex.html">Compiler docs</a></li>
  40. <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
  41. <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
  42. </ul>
  43. </div>
  44. <div id="searchInputDiv">
  45. Search: <input type="search" id="searchInput"
  46. oninput="search()" />
  47. </div>
  48. <ul class="simple simple-toc" id="toc-list">
  49. <li><a class="reference" id="basic-usage_toc" href="#basic-usage">Basic usage</a></li>
  50. <ul class="simple"><li><a class="reference" id="basic-usage-encoding-data_toc" href="#basic-usage-encoding-data">Encoding data</a></li>
  51. <li><a class="reference" id="basic-usage-decoding-data_toc" href="#basic-usage-decoding-data">Decoding data</a></li>
  52. <li><a class="reference" id="basic-usage-url-safe-base64_toc" href="#basic-usage-url-safe-base64">URL Safe Base64</a></li>
  53. </ul><li><a class="reference" id="see-also_toc" href="#see-also">See also</a></li>
  54. <li>
  55. <details open>
  56. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  57. <ul class="simple simple-toc-section">
  58. <ul class="simple nested-toc-section">decode
  59. <li><a class="reference" href="#decode%2Cstring" title="decode(s: string): string">decode(s: string): string</a></li>
  60. </ul>
  61. <ul class="simple nested-toc-section">encode
  62. <li><a class="reference" href="#encode%2CopenArray%5BT%5D" title="encode[T: byte | char](s: openArray[T]; safe = false): string">encode[T: byte | char](s: openArray[T]; safe = false): string</a></li>
  63. <li><a class="reference" href="#encode%2CopenArray%5BT%5D_2" title="encode[T: SomeInteger and not byte](s: openArray[T]; safe = false): string">encode[T: SomeInteger and not byte](s: openArray[T]; safe = false): string</a></li>
  64. </ul>
  65. <ul class="simple nested-toc-section">encodeMime
  66. <li><a class="reference" href="#encodeMime%2Cstring%2Cstring" title="encodeMime(s: string; lineLen = 75.Positive; newLine = &quot;\r\n&quot;; safe = false): string">encodeMime(s: string; lineLen = 75.Positive; newLine = &quot;\r\n&quot;; safe = false): string</a></li>
  67. </ul>
  68. <ul class="simple nested-toc-section">initDecodeTable
  69. <li><a class="reference" href="#initDecodeTable" title="initDecodeTable(): array[256, char]">initDecodeTable(): array[256, char]</a></li>
  70. </ul>
  71. </ul>
  72. </details>
  73. </li>
  74. </ul>
  75. </div>
  76. <div class="nine columns" id="content">
  77. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/base64.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  78. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/base64.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  79. <div id="tocRoot"></div>
  80. <p class="module-desc"><p>This module implements a base64 encoder and decoder.</p>
  81. <p>Unstable API.</p>
  82. <p>Base64 is an encoding and decoding technique used to convert binary data to an ASCII string format. Each Base64 digit represents exactly 6 bits of data. Three 8-bit bytes (i.e., a total of 24 bits) can therefore be represented by four 6-bit Base64 digits.</p>
  83. <h1><a class="toc-backref" id="basic-usage" href="#basic-usage">Basic usage</a></h1>
  84. <h2><a class="toc-backref" id="basic-usage-encoding-data" href="#basic-usage-encoding-data">Encoding data</a></h2>
  85. <p><strong class="examples_text">Example:</strong></p>
  86. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">base64</span>
  87. <span class="Keyword">let</span> <span class="Identifier">encoded</span> <span class="Operator">=</span> <span class="Identifier">encode</span><span class="Punctuation">(</span><span class="StringLit">&quot;Hello World&quot;</span><span class="Punctuation">)</span>
  88. <span class="Identifier">assert</span> <span class="Identifier">encoded</span> <span class="Operator">==</span> <span class="StringLit">&quot;SGVsbG8gV29ybGQ=&quot;</span></pre>Apart from strings you can also encode lists of integers or characters:
  89. <p><strong class="examples_text">Example:</strong></p>
  90. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">base64</span>
  91. <span class="Keyword">let</span> <span class="Identifier">encodedInts</span> <span class="Operator">=</span> <span class="Identifier">encode</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">1'</span><span class="Identifier">u8</span><span class="Punctuation">,</span><span class="DecNumber">2</span><span class="Punctuation">,</span><span class="DecNumber">3</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  92. <span class="Identifier">assert</span> <span class="Identifier">encodedInts</span> <span class="Operator">==</span> <span class="StringLit">&quot;AQID&quot;</span>
  93. <span class="Keyword">let</span> <span class="Identifier">encodedChars</span> <span class="Operator">=</span> <span class="Identifier">encode</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="Punctuation">'</span><span class="Identifier">h</span><span class="CharLit">','</span><span class="Identifier">e</span><span class="CharLit">','</span><span class="Identifier">y</span><span class="CharLit">'])</span>
  94. <span class="Identifier">assert</span> <span class="Identifier">encodedChars</span> <span class="Operator">==</span> <span class="StringLit">&quot;aGV5&quot;</span></pre>
  95. <h2><a class="toc-backref" id="basic-usage-decoding-data" href="#basic-usage-decoding-data">Decoding data</a></h2>
  96. <p><strong class="examples_text">Example:</strong></p>
  97. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">base64</span>
  98. <span class="Keyword">let</span> <span class="Identifier">decoded</span> <span class="Operator">=</span> <span class="Identifier">decode</span><span class="Punctuation">(</span><span class="StringLit">&quot;SGVsbG8gV29ybGQ=&quot;</span><span class="Punctuation">)</span>
  99. <span class="Identifier">assert</span> <span class="Identifier">decoded</span> <span class="Operator">==</span> <span class="StringLit">&quot;Hello World&quot;</span></pre>
  100. <h2><a class="toc-backref" id="basic-usage-url-safe-base64" href="#basic-usage-url-safe-base64">URL Safe Base64</a></h2>
  101. <p><strong class="examples_text">Example:</strong></p>
  102. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">base64</span>
  103. <span class="Identifier">assert</span> <span class="Identifier">encode</span><span class="Punctuation">(</span><span class="StringLit">&quot;c</span><span class="EscapeSequence">\xf7</span><span class="StringLit">&gt;&quot;</span><span class="Punctuation">,</span> <span class="Identifier">safe</span> <span class="Operator">=</span> <span class="Identifier">true</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;Y_c-&quot;</span>
  104. <span class="Identifier">assert</span> <span class="Identifier">encode</span><span class="Punctuation">(</span><span class="StringLit">&quot;c</span><span class="EscapeSequence">\xf7</span><span class="StringLit">&gt;&quot;</span><span class="Punctuation">,</span> <span class="Identifier">safe</span> <span class="Operator">=</span> <span class="Identifier">false</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;Y/c+&quot;</span></pre>
  105. <h1><a class="toc-backref" id="see-also" href="#see-also">See also</a></h1><ul class="simple"><li><a class="reference external" href="hashes.html">hashes module</a> for efficient computations of hash values for diverse Nim types</li>
  106. <li><a class="reference external" href="md5.html">md5 module</a> for the MD5 checksum algorithm</li>
  107. <li><a class="reference external" href="sha1.html">sha1 module</a> for the SHA-1 checksum algorithm</li>
  108. </ul>
  109. </p>
  110. <div class="section" id="12">
  111. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  112. <dl class="item">
  113. <div id="decode-procs-all">
  114. <div id="decode,string">
  115. <dt><pre><span class="Keyword">proc</span> <a href="#decode%2Cstring"><span class="Identifier">decode</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  116. <dd>
  117. <p>Decodes string <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> in base64 representation back into its original form. The initial whitespace is skipped.</p>
  118. <p><strong>See also:</strong></p>
  119. <ul class="simple"><li><a class="reference external" href="#encode,openArray[T]">encode proc</a> for encoding an openarray</li>
  120. </ul>
  121. <p><strong class="examples_text">Example:</strong></p>
  122. <pre class="listing"><span class="Identifier">assert</span> <span class="Identifier">decode</span><span class="Punctuation">(</span><span class="StringLit">&quot;SGVsbG8gV29ybGQ=&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;Hello World&quot;</span>
  123. <span class="Identifier">assert</span> <span class="Identifier">decode</span><span class="Punctuation">(</span><span class="StringLit">&quot; SGVsbG8gV29ybGQ=&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;Hello World&quot;</span></pre>
  124. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/base64.nim#L216" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  125. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/base64.nim#L216" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  126. </dd>
  127. </div>
  128. </div>
  129. <div id="encode-procs-all">
  130. <div id="encode,openArray[T]">
  131. <dt><pre><span class="Keyword">proc</span> <a href="#encode%2CopenArray%5BT%5D"><span class="Identifier">encode</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#byte"><span class="Identifier">byte</span></a> <span class="Operator">|</span> <a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">safe</span> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
  132. <dd>
  133. <p>Encodes <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> into base64 representation.</p>
  134. <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">safe</span></span></tt> is <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> then it will encode using the URL-Safe and Filesystem-safe standard alphabet characters, which substitutes <tt class="docutils literal"><span class="pre"><span class="Operator">-</span></span></tt> instead of <tt class="docutils literal"><span class="pre"><span class="Operator">+</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">_</span></span></tt> instead of <tt class="docutils literal"><span class="pre"><span class="Operator">/</span></span></tt>.</p>
  135. <ul class="simple"><li><a class="reference external" href="https://en.wikipedia.org/wiki/Base64#URL_applications">https://en.wikipedia.org/wiki/Base64#URL_applications</a></li>
  136. <li><a class="reference external" href="https://tools.ietf.org/html/rfc4648#page-7">https://tools.ietf.org/html/rfc4648#page-7</a></li>
  137. </ul>
  138. <p><strong>See also:</strong></p>
  139. <ul class="simple"><li><a class="reference external" href="#decode,string">decode proc</a> for decoding a string</li>
  140. </ul>
  141. <p><strong class="examples_text">Example:</strong></p>
  142. <pre class="listing"><span class="Identifier">assert</span> <span class="Identifier">encode</span><span class="Punctuation">(</span><span class="StringLit">&quot;Hello World&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;SGVsbG8gV29ybGQ=&quot;</span>
  143. <span class="Identifier">assert</span> <span class="Identifier">encode</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="Punctuation">'</span><span class="Identifier">n</span><span class="CharLit">', '</span><span class="Identifier">i</span><span class="CharLit">', '</span><span class="Identifier">m</span><span class="CharLit">']) == &quot;bmlt&quot;</span>
  144. <span class="Identifier">assert</span> <span class="Identifier">encode</span><span class="Punctuation">(</span><span class="Operator">@</span><span class="Punctuation">[</span><span class="Punctuation">'</span><span class="Identifier">n</span><span class="CharLit">', '</span><span class="Identifier">i</span><span class="CharLit">', '</span><span class="Identifier">m</span><span class="CharLit">']) == &quot;bmlt&quot;</span>
  145. <span class="Identifier">assert</span> <span class="Identifier">encode</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">1'</span><span class="Identifier">u8</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;AQIDBAU=&quot;</span></pre>
  146. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/base64.nim#L138" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  147. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/base64.nim#L138" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  148. </dd>
  149. </div>
  150. <div id="encode,openArray[T]_2">
  151. <dt><pre><span class="Keyword">proc</span> <a href="#encode%2CopenArray%5BT%5D_2"><span class="Identifier">encode</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a> <span class="Keyword">and</span> <span class="Keyword">not</span> <a href="system.html#byte"><span class="Identifier">byte</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">safe</span> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
  152. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">deprecated</span><span class="Other">:</span> <span class="StringLit">&quot;use `byte` or `char` instead&quot;</span></span>.}</pre></dt>
  153. <dd>
  154. <div class="deprecation-message">
  155. <b>Deprecated:</b> use `byte` or `char` instead
  156. </div>
  157. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/base64.nim#L157" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  158. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/base64.nim#L157" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  159. </dd>
  160. </div>
  161. </div>
  162. <div id="encodeMime-procs-all">
  163. <div id="encodeMime,string,string">
  164. <dt><pre><span class="Keyword">proc</span> <a href="#encodeMime%2Cstring%2Cstring"><span class="Identifier">encodeMime</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">lineLen</span> <span class="Other">=</span> <span class="DecNumber">75</span><span class="Other">.</span><span class="Identifier">Positive</span><span class="Other">;</span> <span class="Identifier">newLine</span> <span class="Other">=</span> <span class="StringLit">&quot;\r\n&quot;</span><span class="Other">;</span> <span class="Identifier">safe</span> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
  165. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  166. <dd>
  167. <p>Encodes <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> into base64 representation as lines. Used in email MIME format, use <tt class="docutils literal"><span class="pre"><span class="Identifier">lineLen</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">newline</span></span></tt>.</p>
  168. <p>This procedure encodes a string according to MIME spec.</p>
  169. <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">safe</span></span></tt> is <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> then it will encode using the URL-Safe and Filesystem-safe standard alphabet characters, which substitutes <tt class="docutils literal"><span class="pre"><span class="Operator">-</span></span></tt> instead of <tt class="docutils literal"><span class="pre"><span class="Operator">+</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">_</span></span></tt> instead of <tt class="docutils literal"><span class="pre"><span class="Operator">/</span></span></tt>.</p>
  170. <ul class="simple"><li><a class="reference external" href="https://en.wikipedia.org/wiki/Base64#URL_applications">https://en.wikipedia.org/wiki/Base64#URL_applications</a></li>
  171. <li><a class="reference external" href="https://tools.ietf.org/html/rfc4648#page-7">https://tools.ietf.org/html/rfc4648#page-7</a></li>
  172. </ul>
  173. <p><strong>See also:</strong></p>
  174. <ul class="simple"><li><a class="reference external" href="#encode,openArray[T]">encode proc</a> for encoding an openArray</li>
  175. <li><a class="reference external" href="#decode,string">decode proc</a> for decoding a string</li>
  176. </ul>
  177. <p><strong class="examples_text">Example:</strong></p>
  178. <pre class="listing"><span class="Identifier">assert</span> <span class="Identifier">encodeMime</span><span class="Punctuation">(</span><span class="StringLit">&quot;Hello World&quot;</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">,</span> <span class="StringLit">&quot;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;SGVs</span><span class="EscapeSequence">\n</span><span class="StringLit">bG8g</span><span class="EscapeSequence">\n</span><span class="StringLit">V29y</span><span class="EscapeSequence">\n</span><span class="StringLit">bGQ=&quot;</span></pre>
  179. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/base64.nim#L162" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  180. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/base64.nim#L162" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  181. </dd>
  182. </div>
  183. </div>
  184. <div id="initDecodeTable-procs-all">
  185. <div id="initDecodeTable">
  186. <dt><pre><span class="Keyword">proc</span> <a href="#initDecodeTable"><span class="Identifier">initDecodeTable</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#array"><span class="Identifier">array</span></a><span class="Other">[</span><span class="DecNumber">256</span><span class="Other">,</span> <a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  187. <dd>
  188. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/base64.nim#L200" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  189. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/base64.nim#L200" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  190. </dd>
  191. </div>
  192. </div>
  193. </dl>
  194. </div>
  195. </div>
  196. </div>
  197. <div class="twelve-columns footer">
  198. <span class="nim-sprite"></span>
  199. <br>
  200. <small style="color: var(--hint);">Made with Nim. Generated: 2025-01-09 12:00:07 UTC</small>
  201. </div>
  202. </div>
  203. </div>
  204. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  205. </body>
  206. </html>