小さなファイルから何かを読み込み、変更して、同じファイルに書き戻すデーモンを作成しています。私はそれを書き込もうとする前に、各ファイルが読んだ後すぐに閉じられることを確認する必要があります。私はまた、すぐにもう一度読むことがあるので、各ファイルが執筆後すぐに閉じられるようにする必要があります。すぐにファイルが閉じられるようにする
私はバイナリの代わりにバイナリstrictを使用しましたが、厳密なGetを提供するように見えます。 System.IO.Strictと同じ問題です。バイナリで厳密なドキュメントを読んでから、ファイルがすぐに閉じられるようにするという私の問題を本当に解決するかどうかはわかりません。これを処理する最善の方法は何ですか? DeepSeq?
ここでは、私のアプリケーションの構造を理解するための非常に単純化された例を示します。この例は、明らかな理由から、
*** Exception: test.dat: openBinaryFile: resource busy (file is locked)
で終了します。
import Data.Binary (Binary, encode, decode)
import Data.ByteString.Lazy as B (readFile, writeFile)
import Codec.Compression.GZip (compress, decompress)
encodeAndCompressFile :: Binary a => FilePath -> a -> IO()
encodeAndCompressFile f = B.writeFile f . compress . encode
decodeAndDecompressFile :: Binary a => FilePath -> IO a
decodeAndDecompressFile f = return . decode . decompress =<< B.readFile f
main = do
let i = 0 :: Int
encodeAndCompressFile "test.dat" i
doStuff
doStuff = do
i <- decodeAndDecompressFile "test.dat" :: IO Int
print i
encodeAndCompressFile "test.dat" (i+1)
doStuff
恥知らずのプラグイン: 'パイプ'は、約1週間以内に迅速かつ決定論的で構成可能な資源管理を出そろうとしています。 –
@GabrielGonzalez優れています。それがリリースされたら私にpingし、私はこの答えを更新します。 –
完了です。私は[reddit](http://www.reddit.com/r/haskell/comments/txkb0/pipes_20_pipe_finalization/)で発表しました。 –