diff --git a/ChangeLog.md b/ChangeLog.md
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,3 +1,7 @@
+## 0.8.18.7
+
+* Add `O_TRUNC` when opening files
+
 ## 0.8.18.6
 
 * s/fdopen/_fdopen on Windows [#96](https://github.com/snoyberg/yaml/issues/96)
diff --git a/Text/Libyaml.hs b/Text/Libyaml.hs
--- a/Text/Libyaml.hs
+++ b/Text/Libyaml.hs
@@ -511,7 +511,7 @@
 -- XXX copied from GHC.IO.FD
 std_flags, read_flags, output_flags, write_flags :: CInt
 std_flags    = Posix.o_NOCTTY
-output_flags = std_flags    .|. Posix.o_CREAT
+output_flags = std_flags    .|. Posix.o_CREAT .|. Posix.o_TRUNC
 read_flags   = std_flags    .|. Posix.o_RDONLY
 write_flags  = output_flags .|. Posix.o_WRONLY
 
diff --git a/test/Data/YamlSpec.hs b/test/Data/YamlSpec.hs
--- a/test/Data/YamlSpec.hs
+++ b/test/Data/YamlSpec.hs
@@ -34,6 +34,8 @@
 import qualified Data.Vector as V
 import Data.HashMap.Strict (HashMap)
 import qualified Data.HashMap.Strict as HM
+import System.IO (hClose)
+import System.IO.Temp (withSystemTempFile)
 
 data TestJSON = TestJSON
               { string :: Text
@@ -152,7 +154,9 @@
 
     it "preserves Scientific precision" casePreservesScientificPrecision
 
+    it "truncates files" caseTruncatesFiles
 
+
 specialStrings :: [T.Text]
 specialStrings =
     [ "fo\"o"
@@ -502,3 +506,12 @@
     -- results, because of <https://github.com/bos/text/issues/34>.
     D.decodeEither "x: 9.78159610558926e-5" @?= Right (object
         [ "x" .= D.Number (read "9.78159610558926e-5") ])
+
+caseTruncatesFiles :: Assertion
+caseTruncatesFiles = withSystemTempFile "truncate.yaml" $ \fp h -> do
+    replicateM_ 500 $ B8.hPut h "HELLO WORLD!!!!!\n"
+    hClose h
+    let val = object ["hello" .= ("world" :: String)]
+    D.encodeFile fp val
+    res <- D.decodeFileEither fp
+    either (Left . show) Right res `shouldBe` Right val
diff --git a/yaml.cabal b/yaml.cabal
--- a/yaml.cabal
+++ b/yaml.cabal
@@ -1,5 +1,5 @@
 name:            yaml
-version:         0.8.18.6
+version:         0.8.18.7
 license:         BSD3
 license-file:    LICENSE
 author:          Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
@@ -139,6 +139,7 @@
                    , aeson-qq
                    , mockery
                    , base-compat
+                   , temporary
     ghc-options:     -Wall
 
 executable examples
