File tree Expand file tree Collapse file tree
tools/BootstrapBlazor.CssBundler Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- // Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
1+ // Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33// Website: https://www.blazor.zone or https://argozhang.github.io/
44
5+ using System . Buffers ;
56using System . Text ;
67
78namespace BootstrapBlazor . CssBundler ;
@@ -66,14 +67,25 @@ static void DoBundler(string bundlerFile, BundlerOptions option)
6667 {
6768 continue ;
6869 }
69-
70- using var reader = File . OpenText ( inputFile ) ;
71- var content = reader . ReadToEnd ( ) ;
72- writer . Write ( Encoding . UTF8 . GetBytes ( content ) ) ;
73- reader . Close ( ) ;
70+ using var reader = File . OpenRead ( inputFile ) ;
71+ if ( ! IsUtf8Bom ( reader ) )
72+ {
73+ reader . Seek ( 0 , SeekOrigin . Begin ) ;
74+ }
75+ reader . CopyTo ( writer ) ;
7476 }
7577 writer . Close ( ) ;
7678
7779 Console . WriteLine ( $ "Bundler Completed .... { option . OutputFileName } ") ;
7880 }
81+
82+ private static bool IsUtf8Bom ( Stream stream )
83+ {
84+ Span < byte > buffer = stackalloc byte [ 3 ] ;
85+ if ( stream . Read ( buffer ) != buffer . Length )
86+ {
87+ return false ;
88+ }
89+ return buffer . SequenceEqual ( Encoding . UTF8 . GetPreamble ( ) ) ;
90+ }
7991}
You can’t perform that action at this time.
0 commit comments