Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions tools/BootstrapBlazor.CssBundler/Bundler.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -58,21 +58,41 @@ 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<byte>.Shared.Rent(64 * 1024);
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated
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);
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);
}

using var reader = File.OpenText(inputFile);
var content = reader.ReadToEnd();
writer.Write(Encoding.UTF8.GetBytes(content));
reader.Close();
while (reader.Position < reader.Length)
{
read = reader.Read(buffer, 0, buffer.Length);
writer.Write(buffer, 0, read);
}
}
writer.Close();
Comment thread
ArgoZhang marked this conversation as resolved.
Outdated
Comment thread
ArgoZhang marked this conversation as resolved.
Outdated
}
finally
{
ArrayPool<byte>.Shared.Return(buffer);
Comment thread
ArgoZhang marked this conversation as resolved.
Outdated
}
writer.Close();

Console.WriteLine($"Bundler Completed .... {option.OutputFileName}");
}
Expand Down