Skip to content

Commit 2cad878

Browse files
chrisdonepaf31
authored andcommitted
Strict handling of UTF8 files (fixes fd issue) (purescript#2338)
* Strict handling of UTF8 files (fixes fd issue) * Update CONTRIBUTORS.md
1 parent ac9ad9a commit 2cad878

2 files changed

Lines changed: 5 additions & 15 deletions

File tree

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This file lists the contributors to the PureScript compiler project, and the ter
1818
- [@bsermons](https://github.com/bsermons) (Brian Sermons) My existing contributions and all future contributions until further notice are Copyright Brian Sermons, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
1919
- [@cdepillabout](https://github.com/cdepillabout) (Dennis Gosnell) My existing contributions and all future contributions until further notice are Copyright Dennis Gosnell, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
2020
- [@charleso](https://github.com/charleso) (Charles O'Farrell) My existing contributions to the PureScript compiler and all future contributions to the PureScript compiler until further notice, are Copyright Charles O'Farrell, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
21+
- [@chrisdone](https://github.com/chrisdone) (Chris Done) - My existing contributions and all future contributions until further notice are Copyright Chris Done, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
2122
- [@chrissmoak](https://github.com/chrissmoak) (Chris Smoak) My existing contributions to the PureScript compiler and all future contributions to the PureScript compiler until further notice, are Copyright Chris Smoak, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
2223
- [@codedmart](https://github.com/codedmart) (Brandon Martin) My existing contributions and all future contributions until further notice are Copyright Brandon Martin, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
2324
- [@davidchambers](https://github.com/davidchambers) (David Chambers) My existing contributions and all future contributions until further notice are Copyright David Chambers, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).

src/System/IO/UTF8.hs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,13 @@ module System.IO.UTF8 where
22

33
import Prelude.Compat
44

5-
import System.IO ( IOMode(..)
6-
, hGetContents
7-
, hSetEncoding
8-
, hClose
9-
, hPutStr
10-
, openFile
11-
, utf8
12-
)
5+
import qualified Data.ByteString as BS
6+
import qualified Data.ByteString.UTF8 as UTF8
137

148
readUTF8File :: FilePath -> IO String
159
readUTF8File inFile = do
16-
h <- openFile inFile ReadMode
17-
hSetEncoding h utf8
18-
hGetContents h
10+
fmap UTF8.toString (BS.readFile inFile)
1911

2012
writeUTF8File :: FilePath -> String -> IO ()
2113
writeUTF8File inFile text = do
22-
h <- openFile inFile WriteMode
23-
hSetEncoding h utf8
24-
hPutStr h text
25-
hClose h
14+
BS.writeFile inFile (UTF8.fromString text)

0 commit comments

Comments
 (0)