claunia / plist-cil

C#/.NET parser for Apple and GnuStep Property List (aka plist), based on Java's dd-plist
Other
56 stars 17 forks source link

Save to XXX issue #28

Open abcjjy opened 6 years ago

abcjjy commented 6 years ago
    public static void SaveAsASCII(NSArray root, FileInfo outFile)
        {
            string parent = outFile.DirectoryName;
            if (!Directory.Exists(parent))
                Directory.CreateDirectory(parent);
            using (Stream fous = outFile.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite))
            using (StreamWriter w = new StreamWriter(fous, Encoding.ASCII))
            {
                w.Write(root.ToASCIIPropertyList());
            }
        }

It is not a full overwrite in case writing to an existing file and leaves an invalid file.

abcjjy commented 6 years ago

Following line will fix

fous.SetLength(0);

claunia commented 6 years ago

@abcjjy acknowledged, I'll take a look as soon as I can.