초기 커밋.

This commit is contained in:
2024-11-06 00:26:39 +09:00
parent 22b9f72198
commit bb5f6d6cd6
3 changed files with 197 additions and 0 deletions

25
Ttalkkak.sln Normal file
View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ttalkkak", "Ttalkkak\Ttalkkak.csproj", "{1986B594-0AD0-4ABA-8243-D06F0F85E1A8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1986B594-0AD0-4ABA-8243-D06F0F85E1A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1986B594-0AD0-4ABA-8243-D06F0F85E1A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1986B594-0AD0-4ABA-8243-D06F0F85E1A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1986B594-0AD0-4ABA-8243-D06F0F85E1A8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FA1252FD-2B8A-482A-BD96-2EA42BD68EB9}
EndGlobalSection
EndGlobal

156
Ttalkkak/Program.cs Normal file
View File

@@ -0,0 +1,156 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Security.Cryptography;
using System.Threading.Tasks;
using K4os.Compression.LZ4.Streams;
using Minio;
using Minio.DataModel;
using Minio.DataModel.Args;
using Minio.DataModel.Encryption;
using Minio.Exceptions;
class Program
{
static async Task Main(string[] args)
{
//Console.WriteLine("Hello, World!");
// Minio 설정 (Minio 클라이언트 인스턴스 생성)
IWebProxy proxy = new WebProxy("https://a4plane.duckdns.org", 443);
IMinioClient minioClient = new MinioClient()
.WithEndpoint("a4plane.duckdns.org")
.WithCredentials("a4plane", "661434Ghkd")
.WithSSL()
.WithProxy(proxy)
.Build();
// 압축 및 업로드할 폴더 및 파일 경로 설정
string sourceFolder = "testo";
string bucketName = "testob";
string objectName = "testtt.lz4";
string outputLz4File = Path.Combine(Directory.GetCurrentDirectory(), objectName);
// 폴더를 압축
CompressFolderWithProgress(sourceFolder, outputLz4File);
// 압축한 파일을 Minio로 업로드
await UploadWithProgress((MinioClient)minioClient, bucketName, objectName, outputLz4File);
}
static void CompressFolderWithProgress(string sourceFolder, string outputLz4File)
{
string tempZipFile = Path.GetTempFileName();
try
{
// 압축 전 폴더 확인
if (!Directory.Exists(sourceFolder))
{
Console.WriteLine($"오류: '{sourceFolder}' 폴더가 존재하지 않습니다.");
return;
}
if (File.Exists(tempZipFile))
{
Console.WriteLine($"경고: '{tempZipFile}' 파일이 이미 존재합니다. 덮어씁니다.");
File.Delete(tempZipFile);
}
// ZIP 파일 압축
ZipFile.CreateFromDirectory(sourceFolder, tempZipFile, CompressionLevel.Fastest, false);
Console.WriteLine("ZIP 압축 완료");
// ZIP -> LZ4 압축
var zipFileInfo = new FileInfo(tempZipFile);
long zipFileSize = zipFileInfo.Length;
long processedSize = 0;
using var zipFileStream = File.OpenRead(tempZipFile);
using var outputFileStream = File.Create(outputLz4File);
using var lz4Stream = LZ4Stream.Encode(outputFileStream);
var buffer = new byte[8192];
int bytesRead;
while ((bytesRead = zipFileStream.Read(buffer, 0, buffer.Length)) > 0)
{
lz4Stream.Write(buffer, 0, bytesRead);
processedSize += bytesRead;
int progress = (int)(100 * processedSize / zipFileSize);
Console.Write($"\rLZ4 압축 진행도: {progress}%");
}
Console.WriteLine("\nLZ4 압축 완료");
}
catch (Exception ex)
{
Console.WriteLine($"오류 발생: {ex.Message}");
}
finally
{
if (File.Exists(tempZipFile))
{
File.Delete(tempZipFile);
}
}
}
// 폴더의 전체 파일 크기를 계산하는 메서드
static long CalculateFolderSize(string folder)
{
long size = 0;
foreach (var filePath in Directory.GetFiles(folder, "*", SearchOption.AllDirectories))
{
var fileInfo = new FileInfo(filePath);
size += fileInfo.Length;
}
return size;
}
static async Task UploadWithProgress(MinioClient minio, string bucketName, string objectName, string filePath)
{
try
{
Aes aesEncryption = Aes.Create();
aesEncryption.KeySize = 256;
aesEncryption.GenerateKey();
var ssec = new SSEC(aesEncryption.Key);
var progress = new Progress<ProgressReport>(progressReport =>
{
// Progress events are delivered asynchronously (see remark below)
Console.WriteLine(
$"Percentage: {progressReport.Percentage}% TotalBytesTransferred: {progressReport.TotalBytesTransferred} bytes");
if (progressReport.Percentage != 100)
Console.SetCursorPosition(0, Console.CursorTop - 1);
else Console.WriteLine();
});
var putObjectArgs = new PutObjectArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithFileName(filePath)
.WithContentType("application/octet-stream")
.WithServerSideEncryption(ssec)
.WithProgress(progress);
if (putObjectArgs == null)
{
Console.WriteLine("putObjectArgs is null.");
return; // 혹은 예외를 던지는 방법으로 조치
}
if (minio == null)
{
Console.WriteLine("MinioClient is null.");
}
Console.WriteLine($"Bucket Name: {bucketName}, Object Name: {objectName}, File Path: {filePath}");
await minio.PutObjectAsync(putObjectArgs);
Console.WriteLine($"{objectName} is uploaded successfully.");
}
catch (MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
}
}

16
Ttalkkak/Ttalkkak.csproj Normal file
View File

@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="K4os.Compression.LZ4" Version="1.3.8" />
<PackageReference Include="K4os.Compression.LZ4.Streams" Version="1.3.8" />
<PackageReference Include="Minio" Version="6.0.3" />
</ItemGroup>
</Project>