monad-lab / study

2 stars 1 forks source link

[ch.9] 내가 읽는 파일이 텍스트인지 바이너리 파일인지 어찌 설정하나요? #70

Open y30n9ju1v opened 7 months ago

y30n9ju1v commented 7 months ago

image

그리고 바이너리를 쓰려면요?

py6578 commented 7 months ago

https://stackoverflow.com/questions/32253948/haskell-read-write-binary-files-complete-working-example

찌찌뽕.. 같은 생각했슴다..

py6578 commented 7 months ago

ghci> :t withBinaryFile withBinaryFile :: FilePath -> System.IO.IOMode -> (Handle -> IO r) -> IO r

-- TODO: implement as for POSIX withFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r withFile = POSIX.withFile <!> wf where wf path mode act = bracket (Win.openFile path mode) hClose_impl act

openBinaryFile :: FilePath -> IOMode -> IO Handle openBinaryFile = POSIX.openBinaryFile <!> Win.openBinaryFile

withBinaryFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r withBinaryFile = POSIX.withBinaryFile <!> wf where wf path mode act = bracket (Win.openBinaryFile path mode) hClose_impl act