Skip to content

Commit 29f554f

Browse files
committed
Extended FileDataProcessing pipeline with Metadata
- fixed problem with output for large files - added WebClient to better handle large files - variable cleanup for better memory usage
1 parent 59b6fcc commit 29f554f

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

Slack.Backup/Private/backup/Invoke-FilesBackup.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ function Invoke-FilesBackup {
2929
$ext = $f.filetype
3030
$path = "$backupLoc/$($f.id)"
3131
$slackFile = Get-SlackFile -Token $Token -Uri $f.url_private
32-
$slackFile = Invoke-FileDataProcessingPipeline -SlackFile $slackFile
32+
$slackFile = Invoke-FileDataProcessingPipeline -SlackFile $slackFile -Metadata $f
3333
[System.IO.File]::WriteAllBytes("$path.$ext", $slackFile)
34+
Remove-Variable -Name slackFile
3435
$f | Invoke-FileProcessingPipeline | ConvertTo-Json -Depth 10 | Set-Content -Path "$path.json"
3536
}
3637
}

Slack.Backup/Private/pipelines/Invoke-FileDataProcessingPipeline.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
function Invoke-FileDataProcessingPipeline {
22
param (
33
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true )]
4-
[byte[]]$SlackFile
4+
[byte[]]$SlackFile,
5+
[Parameter(Mandatory = $true, Position = 1 )]
6+
[System.Object]$Metadata
57
)
68
process {
79
Get-PipelineProcessor -Name Invoke-FileDataProcessor* -Parameters @( @{Name = "SlackFile"; Type = [byte[]] } ) | % {
810
Write-Verbose "Invoking processor: $($_.Name)"
9-
$SlackFile = &($_.Name) -SlackFile $SlackFile
11+
$SlackFile = &($_.Name) -SlackFile $SlackFile -Metadata $Metadata
1012
}
1113
$SlackFile
1214
}

Slack.Backup/Public/Get-SlackFile.ps1

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
class Net {
2+
hidden static [Net] $_instance = [Net]::new()
3+
static [Net] $Instance = [Net]::GetInstance()
4+
5+
6+
[Net.WebClient]$WebClient = [Net.WebClient]::new()
7+
8+
hidden Net() {}
9+
10+
hidden static [Net] GetInstance() {
11+
return [Net]::_instance
12+
}
13+
}
114
function Get-SlackFile {
215
[CmdletBinding()]
316
param (
@@ -18,8 +31,14 @@ function Get-SlackFile {
1831
$headers = Get-RequestHeader $Token
1932
if ($OutFile) {
2033
Invoke-WebRequest -Method Get -Uri $Uri -Headers $headers -OutFile $OutFile
21-
}else{
22-
Invoke-WebRequest -Method Get -Uri $Uri -Headers $headers | Select-Object -ExpandProperty Content
34+
}
35+
else {
36+
[Net]::Instance.WebClient.Headers.Clear()
37+
$headers.Keys | % {
38+
[Net]::Instance.WebClient.Headers.Add($_, $headers[$_])
39+
}
40+
[byte[]]$response = [Net]::Instance.WebClient.DownloadData($Uri)
41+
Write-Output $response -NoEnumerate
2342
}
2443
}
2544

Tests/Slack.Backup.Tests.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ $script:processorInvoked = $false
1010
function Invoke-FileDataProcessorMock {
1111
param (
1212
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true )]
13-
[byte[]]$SlackFile
13+
[byte[]]$SlackFile,
14+
[Parameter(Mandatory = $true, Position = 1 )]
15+
[System.Object]$Metadata
1416
)
1517
$script:processorInvoked = $true
1618
$SlackFile

0 commit comments

Comments
 (0)