Note that there are some explanatory texts on larger screens.

plurals
  1. POData.ByteString.Lazy.Char8 newline conversion on Windows---is the documentation misleading?
    primarykey
    data
    text
    <p>I have a question about the Data.ByteString.Lazy.Char8 library in the bytestring library. Specifically, my question concerns the readFile function, which is documented as follows:</p> <blockquote> <p>Read an entire file lazily into a ByteString. Use 'text mode' on Windows to interpret newlines </p> </blockquote> <p>I'm interested in the claim that this function will 'use text mode on Windows to interpret newlines'. The source code for the function is as follows:</p> <pre><code>-- | Read an entire file /lazily/ into a 'ByteString'. Use 'text mode' -- on Windows to interpret newlines readFile :: FilePath -&gt; IO ByteString readFile f = openFile f ReadMode &gt;&gt;= hGetContents </code></pre> <p>and we see that, in one sense, the claim in the documentation is perfectly true: the <code>openFile</code> function (as opposed to <code>openBinaryFile</code>) has been used, and so newline conversion will be enabled for the file. </p> <p><em>But</em>, the file will then be passed to hGetContents. This will call <code>Data.ByteString.hGetNonBlocking</code> (see the source code <a href="http://hackage.haskell.org/packages/archive/bytestring/0.9.1.5/doc/html/src/Data-ByteString-Lazy.html#hGetContents" rel="nofollow">here</a> and <a href="http://hackage.haskell.org/packages/archive/bytestring/0.9.1.5/doc/html/src/Data-ByteString-Lazy.html#hGetContentsN" rel="nofollow">here</a>), which is meant to be a non blocking version of <code>Data.ByteString.hGet</code> (see <a href="http://hackage.haskell.org/packages/archive/bytestring/0.9.1.7/doc/html/Data-ByteString.html#v%3ahGetNonBlocking" rel="nofollow">the documentation</a>); and (finally) <code>Data.ByteString.hGet</code> calls <code>GHC.IO.Handle.hGetBuf</code> (see <a href="http://hackage.haskell.org/packages/archive/bytestring/0.9.1.7/doc/html/Data-ByteString.html#v%3ahGet" rel="nofollow">the documentation</a> or <a href="http://hackage.haskell.org/packages/archive/bytestring/0.9.1.7/doc/html/src/Data-ByteString.html#hGet" rel="nofollow">the source code</a>). This function's <a href="http://hackage.haskell.org/packages/archive/base/4.2.0.2/doc/html/GHC-IO-Handle.html#v%3ahGetBuf" rel="nofollow">documentation</a> says that </p> <blockquote> <p>hGetBuf ignores whatever TextEncoding the Handle is currently using, and reads bytes directly from the underlying IO device.</p> </blockquote> <p>which suggests that the fact that we opened the file using <code>readFile</code> rather than <code>readBinaryFile</code> is irrelevant: the data will be read without transforming newlines, notwithstanding the claim in the documentation referred to at the beginning of the question.</p> <p>So, the nub of the question: 1. Am I missing something? Is there some sense in which the statement 'that Data.ByteString.Lazy.Char8.readFile uses text mode on Windows to interpret newlines' is true? Or is the documentation just misleading?</p> <p>P.S. Testing also indicates that this function, at least when used naively as I was using it, does no newline conversion on Windows.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload