{"route":"/en-US-v0.14.1/reference/data-loading/read/","title":"Read","description":"Documentation for the `read` function.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"example","name":"Example","children":[]},{"id":"parameters","name":"Parameters","children":[{"id":"parameters-path","name":"path","children":[]},{"id":"parameters-encoding","name":"encoding","children":[]}]}],"body":{"kind":"func","content":{"path":[],"name":"read","title":"Read","keywords":[],"oneliner":"Reads plain text or data from a file.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Reads plain text or data from a file.</p>\n<p>By default, the file will be read as UTF-8 and returned as a <a href=\"/en-US-v0.14.1/reference/foundations/str/\">string</a>.</p>\n<p>If you specify <code>encoding: <span class=\"typ-key\">none</span></code>, this returns raw <a href=\"/en-US-v0.14.1/reference/foundations/bytes/\" title=\"bytes\">bytes</a> instead.</p>\n<h2 id=\"example\">Example</h2>\n<div class=\"previewed-code\"><pre><code>An example for a HTML file: <span class=\"typ-escape\">\\</span>\n<span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> text <span class=\"typ-op\">=</span> <span class=\"typ-func\">read</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;example.html&quot;</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">raw</span><span class=\"typ-punct\">(</span>text<span class=\"typ-punct\">,</span> lang<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;html&quot;</span><span class=\"typ-punct\">)</span>\n\nRaw bytes:\n<span class=\"typ-func\">#</span><span class=\"typ-func\">read</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;tiger.jpg&quot;</span><span class=\"typ-punct\">,</span> encoding<span class=\"typ-punct\">:</span> <span class=\"typ-key\">none</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/b92e43ad9c335363c8a8efef74973b19.png\" alt=\"Preview\"></div></div>"}],"self":false,"params":[{"name":"path","details":[{"kind":"html","content":"<p>Path to a file.</p>\n<p>For more details, see the <a href=\"/en-US-v0.14.1/reference/syntax/#paths\">Paths section</a>.</p>"}],"types":["str"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"encoding","details":[{"kind":"html","content":"<p>The encoding to read the file with.</p>\n<p>If set to <code><span class=\"typ-key\">none</span></code>, this function returns raw bytes.</p>"}],"types":["none","str"],"strings":[{"string":"utf8","details":"<p>The Unicode UTF-8 encoding.</p>"}],"default":"<code><span class=\"typ-str\">&quot;utf8&quot;</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["str","bytes"],"scope":[]}}}