From abfd13cf54455bbfdcde2ba0af438dec0a7c921c Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 10 Nov 2025 12:53:09 +0800 Subject: [PATCH 1/5] =?UTF-8?q?refactor:=20=E4=BD=BF=E7=94=A8=E6=B5=81?= =?UTF-8?q?=E6=8F=90=E9=AB=98=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/BootstrapBlazor.CssBundler/Bundler.cs | 47 +++++++++++++++------ 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/tools/BootstrapBlazor.CssBundler/Bundler.cs b/tools/BootstrapBlazor.CssBundler/Bundler.cs index bece4236..2e9541ea 100644 --- a/tools/BootstrapBlazor.CssBundler/Bundler.cs +++ b/tools/BootstrapBlazor.CssBundler/Bundler.cs @@ -1,8 +1,8 @@ -// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. +// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Website: https://www.blazor.zone or https://argozhang.github.io/ -using System.Text; +using System.Buffers; namespace BootstrapBlazor.CssBundler; @@ -58,21 +58,42 @@ static void DoBundler(string bundlerFile, BundlerOptions option) return; } - using var writer = File.OpenWrite(Path.Combine(rootFolder, option.OutputFileName)); - foreach (var file in option.InputFiles) + var buffer = ArrayPool.Shared.Rent(64 * 1024 * 1024); + try { - var inputFile = Path.Combine(rootFolder, file); - if (!File.Exists(inputFile)) + using var writer = File.OpenWrite(Path.Combine(rootFolder, option.OutputFileName)); + foreach (var file in option.InputFiles) { - continue; - } + var inputFile = Path.Combine(rootFolder, file); + if (!File.Exists(inputFile)) + { + continue; + } + + using var reader = File.OpenRead(inputFile); + while (true) + { + var read = reader.Read(buffer, 0, buffer.Length); + if (read == 0) + { + break; + } - using var reader = File.OpenText(inputFile); - var content = reader.ReadToEnd(); - writer.Write(Encoding.UTF8.GetBytes(content)); - reader.Close(); + if (reader.Position == read && read >= 3 && buffer[0] == 0xEF && buffer[1] == 0xBB && buffer[2] == 0xBF) + { + // skip bom + writer.Write(buffer, 3, read - 3); + continue; + } + writer.Write(buffer, 0, read); + } + } + writer.Close(); + } + finally + { + ArrayPool.Shared.Return(buffer); } - writer.Close(); Console.WriteLine($"Bundler Completed .... {option.OutputFileName}"); } From fe31910eb8ea4026ba443262336232f02fae91df Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 10 Nov 2025 13:05:14 +0800 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20=E6=8F=90=E9=AB=98=E6=80=A7?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/BootstrapBlazor.CssBundler/Bundler.cs | 23 ++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tools/BootstrapBlazor.CssBundler/Bundler.cs b/tools/BootstrapBlazor.CssBundler/Bundler.cs index 2e9541ea..13608647 100644 --- a/tools/BootstrapBlazor.CssBundler/Bundler.cs +++ b/tools/BootstrapBlazor.CssBundler/Bundler.cs @@ -71,20 +71,19 @@ static void DoBundler(string bundlerFile, BundlerOptions option) } using var reader = File.OpenRead(inputFile); - while (true) + var read = reader.Read(buffer, 0, buffer.Length); + if (read >= 3 && buffer[0] == 0xEF && buffer[1] == 0xBB && buffer[2] == 0xBF) { - var read = reader.Read(buffer, 0, buffer.Length); - if (read == 0) - { - break; - } + writer.Write(buffer, 3, read - 3); + } + else + { + writer.Write(buffer, 0, read); + } - if (reader.Position == read && read >= 3 && buffer[0] == 0xEF && buffer[1] == 0xBB && buffer[2] == 0xBF) - { - // skip bom - writer.Write(buffer, 3, read - 3); - continue; - } + while (reader.Position < reader.Length) + { + read = reader.Read(buffer, 0, buffer.Length); writer.Write(buffer, 0, read); } } From 0b8c491458d3ecd2820459525213cc87cf1a9026 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 10 Nov 2025 13:06:46 +0800 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=94=B9=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/BootstrapBlazor.CssBundler/Bundler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/BootstrapBlazor.CssBundler/Bundler.cs b/tools/BootstrapBlazor.CssBundler/Bundler.cs index 13608647..532cda2a 100644 --- a/tools/BootstrapBlazor.CssBundler/Bundler.cs +++ b/tools/BootstrapBlazor.CssBundler/Bundler.cs @@ -58,7 +58,7 @@ static void DoBundler(string bundlerFile, BundlerOptions option) return; } - var buffer = ArrayPool.Shared.Rent(64 * 1024 * 1024); + var buffer = ArrayPool.Shared.Rent(64 * 1024); try { using var writer = File.OpenWrite(Path.Combine(rootFolder, option.OutputFileName)); From dd958bcfdae23d795f6fc13ce82b9da7004db567 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 10 Nov 2025 13:17:26 +0800 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/BootstrapBlazor.CssBundler/Bundler.cs | 54 +++++++++------------ 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/tools/BootstrapBlazor.CssBundler/Bundler.cs b/tools/BootstrapBlazor.CssBundler/Bundler.cs index 532cda2a..061dde33 100644 --- a/tools/BootstrapBlazor.CssBundler/Bundler.cs +++ b/tools/BootstrapBlazor.CssBundler/Bundler.cs @@ -3,6 +3,7 @@ // Website: https://www.blazor.zone or https://argozhang.github.io/ using System.Buffers; +using System.Text; namespace BootstrapBlazor.CssBundler; @@ -58,42 +59,33 @@ static void DoBundler(string bundlerFile, BundlerOptions option) return; } - var buffer = ArrayPool.Shared.Rent(64 * 1024); - try + using var writer = File.OpenWrite(Path.Combine(rootFolder, option.OutputFileName)); + foreach (var file in option.InputFiles) { - using var writer = File.OpenWrite(Path.Combine(rootFolder, option.OutputFileName)); - foreach (var file in option.InputFiles) + var inputFile = Path.Combine(rootFolder, file); + if (!File.Exists(inputFile)) { - var inputFile = Path.Combine(rootFolder, file); - if (!File.Exists(inputFile)) - { - continue; - } - - using var reader = File.OpenRead(inputFile); - var read = reader.Read(buffer, 0, buffer.Length); - if (read >= 3 && buffer[0] == 0xEF && buffer[1] == 0xBB && buffer[2] == 0xBF) - { - writer.Write(buffer, 3, read - 3); - } - else - { - writer.Write(buffer, 0, read); - } - - while (reader.Position < reader.Length) - { - read = reader.Read(buffer, 0, buffer.Length); - writer.Write(buffer, 0, read); - } + continue; } - writer.Close(); - } - finally - { - ArrayPool.Shared.Return(buffer); + using var reader = File.OpenRead(inputFile); + if (IsUtf8Bom(reader)) + { + reader.Seek(0, SeekOrigin.Begin); + } + reader.CopyTo(writer); } + writer.Close(); Console.WriteLine($"Bundler Completed .... {option.OutputFileName}"); } + + private static bool IsUtf8Bom(Stream stream) + { + Span buffer = stackalloc byte[3]; + if (stream.Read(buffer) != buffer.Length) + { + return false; + } + return buffer.SequenceEqual(Encoding.UTF8.GetPreamble()); + } } From c050deeb68d05e38e3a1b89e73a0cba4945a0d7e Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 10 Nov 2025 13:27:35 +0800 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=AD=A3=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/BootstrapBlazor.CssBundler/Bundler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/BootstrapBlazor.CssBundler/Bundler.cs b/tools/BootstrapBlazor.CssBundler/Bundler.cs index 061dde33..76abc9bb 100644 --- a/tools/BootstrapBlazor.CssBundler/Bundler.cs +++ b/tools/BootstrapBlazor.CssBundler/Bundler.cs @@ -68,7 +68,7 @@ static void DoBundler(string bundlerFile, BundlerOptions option) continue; } using var reader = File.OpenRead(inputFile); - if (IsUtf8Bom(reader)) + if (!IsUtf8Bom(reader)) { reader.Seek(0, SeekOrigin.Begin); }