mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-08-21 15:54:06 +02:00
.config
.run
.workdir
Agent
Common
Controller
Docker
Utils
Phantom.Utils
Collections
Cryptography
IO
Chmod.cs
Directories.cs
FileSize.cs
Files.cs
Paths.cs
StreamCopier.cs
Processes
Runtime
Tasks
Threading
Phantom.Utils.csproj
Phantom.Utils.Events
Phantom.Utils.Logging
Phantom.Utils.Rpc
Phantom.Utils.Tests
Web
.dockerignore
.gitattributes
.gitignore
AddMigration.bat
AddMigration.sh
Directory.Build.props
Directory.Build.targets
Dockerfile
LICENSE
Packages.props
PhantomPanel.sln
README.md
global.json
27 lines
804 B
C#
27 lines
804 B
C#
namespace Phantom.Utils.IO;
|
|
|
|
public static class Files {
|
|
public static async Task WriteBytesAsync(string path, ReadOnlyMemory<byte> bytes, FileMode mode, UnixFileMode chmod) {
|
|
var options = new FileStreamOptions {
|
|
Mode = mode,
|
|
Access = FileAccess.Write,
|
|
Options = FileOptions.Asynchronous,
|
|
Share = FileShare.Read
|
|
};
|
|
|
|
if (!OperatingSystem.IsWindows()) {
|
|
options.UnixCreateMode = chmod;
|
|
}
|
|
|
|
await using var stream = new FileStream(path, options);
|
|
await stream.WriteAsync(bytes);
|
|
}
|
|
|
|
public static void RequireMaximumFileSize(string path, long maximumBytes) {
|
|
var actualBytes = new FileInfo(path).Length;
|
|
if (actualBytes > maximumBytes) {
|
|
throw new IOException("Expected file size to be at most " + maximumBytes + " B, actual size is " + actualBytes + " B.");
|
|
}
|
|
}
|
|
}
|