Example #1
0
        private static void WriteBytesToFile(string folder, string name, ArraySegment <byte> bytes, SourceMapBuilder sourceMapBuilder = null)
        {
            var filePath = Path.Combine(folder, name);
            var fileMode = File.Exists(filePath) ? FileMode.Truncate : FileMode.CreateNew;

            EnsureDirectoryExists(Path.GetDirectoryName(filePath));

            bool writeMapLink = sourceMapBuilder != null && sourceMapBuilder.Build(folder, name);

            using (var fs = File.Open(filePath, fileMode, FileAccess.Write, FileShare.Read))
            {
                fs.Write(bytes.Array, bytes.Offset, bytes.Count);
                if (writeMapLink)
                {
                    sourceMapBuilder.WriteSourceMapLink(fs, folder, name);
                }
                fs.Flush();
            }
        }