-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_files.ps1
78 lines (64 loc) · 2.35 KB
/
create_files.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Fonction pour générer un nom aléatoire
function Get-RandomFileName {
return [System.IO.Path]::GetRandomFileName().Replace(".", "") + ".bin"
}
# Fonction pour générer un contenu aléatoire de 4KB
function Get-RandomContent {
$bytes = New-Object byte[] 4096
$rng = New-Object System.Security.Cryptography.RNGCryptoServiceProvider
$rng.GetBytes($bytes)
return $bytes
}
# Fonction pour calculer le hash SHA256
function Get-FastHash {
param([string]$filePath)
$sha256 = [System.Security.Cryptography.SHA256]::Create()
$fileStream = [System.IO.File]::OpenRead($filePath)
try {
return [System.BitConverter]::ToString($sha256.ComputeHash($fileStream)).Replace("-", "").ToLower()
}
finally {
$fileStream.Dispose()
$sha256.Dispose()
}
}
# Création du répertoire principal
$mainDir = New-Item -ItemType Directory -Path ".\GeneratedFiles" -Force
$manifestDir = New-Item -ItemType Directory -Path "$($mainDir.FullName)\Manifest" -Force
# Liste pour stocker les informations des fichiers
$fileInfos = @()
# Mesure du temps de début
$sw = [System.Diagnostics.Stopwatch]::StartNew()
# Génération des 400 fichiers .bin
1..400 | ForEach-Object {
$fileName = Get-RandomFileName
$filePath = Join-Path $mainDir.FullName $fileName
$content = Get-RandomContent
[System.IO.File]::WriteAllBytes($filePath, $content)
$fileInfos += @{
Path = $filePath
Name = $fileName
}
}
# Création des 400 fichiers manifestes
1..400 | ForEach-Object {
# Sélection aléatoire de 20 fichiers
$selectedFiles = $fileInfos | Get-Random -Count 20
$manifestContent = @{
Resources = $selectedFiles | ForEach-Object {
@{
Id = $_.Name # Utilisation du nom du fichier comme Id au lieu d'un GUID
Size = (Get-Item $_.Path).Length / 1024 # Taille en Ko
Version = "1"
Hash = Get-FastHash $_.Path
}
}
} | ConvertTo-Json -Depth 10
$manifestPath = Join-Path $manifestDir.FullName "manifest_$_.json"
[System.IO.File]::WriteAllText($manifestPath, $manifestContent)
}
$sw.Stop()
# Affichage des résultats
Write-Host "Opération terminée en $($sw.ElapsedMilliseconds) ms"
Write-Host "Fichiers générés dans: $($mainDir.FullName)"
Write-Host "Manifestes générés dans: $($manifestDir.FullName)"