mirror of
https://github.com/pesde-pkg/tooling.git
synced 2025-01-09 15:59:09 +00:00
feat(lib): only download asset when it is of a valid format
Small optimization to not fetch an asset if its need of a supported compression format.
This commit is contained in:
parent
f003ce8895
commit
45627ea4a9
2 changed files with 15 additions and 11 deletions
|
@ -46,17 +46,15 @@ local function downloadAndDecompress(asset: {
|
||||||
size: number,
|
size: number,
|
||||||
content_type: string,
|
content_type: string,
|
||||||
}): Option<pathfs.Path>
|
}): Option<pathfs.Path>
|
||||||
-- TODO: Small optimization by first detecting that its a valid format we support
|
|
||||||
-- before downloading the file
|
|
||||||
local contentsResp = net.request(asset.browser_download_url)
|
|
||||||
if not contentsResp.ok then
|
|
||||||
return error(`Failed to download asset {asset.name}: HTTP Code {contentsResp.statusCode}`)
|
|
||||||
end
|
|
||||||
|
|
||||||
return compression
|
return compression
|
||||||
.detectFormat(asset.name)
|
.detectFormat(asset.name)
|
||||||
:map(function(format: compression.CompressionFormat)
|
:andThen(function(format: compression.CompressionFormat)
|
||||||
return compression.decompress[format](buffer.fromstring(contentsResp.body)):unwrap() :: pathfs.Path
|
local contentsResp = net.request(asset.browser_download_url)
|
||||||
|
if not contentsResp.ok then
|
||||||
|
return error(`Failed to download asset {asset.name}: HTTP Code {contentsResp.statusCode}`)
|
||||||
|
end
|
||||||
|
|
||||||
|
return compression.decompress[format](buffer.fromstring(contentsResp.body)):ok() :: Option<pathfs.Path>
|
||||||
end) :: Option<pathfs.Path>
|
end) :: Option<pathfs.Path>
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,14 +7,20 @@ local Option = {}
|
||||||
local Result = {}
|
local Result = {}
|
||||||
|
|
||||||
export type Option<T> = OptionImpl.Option<T> & typeof(Option)
|
export type Option<T> = OptionImpl.Option<T> & typeof(Option)
|
||||||
export type Result<T, E> = ResultImpl.Result<T, E>
|
export type Result<T, E> = ResultImpl.Result<T, E> & typeof(Result)
|
||||||
|
|
||||||
function Option.okOr<T, E>(self: Option<T>, err: E): Result<T, E>
|
function Option.okOr<T, E>(self: Option<T>, err: E): Result<T, E>
|
||||||
return self:mapOrElse(function()
|
return self:mapOrElse(function()
|
||||||
return ResultImpl.Err(err)
|
return ResultImpl.Err(err)
|
||||||
end, function(val)
|
end, function(val)
|
||||||
return ResultImpl.Ok(val)
|
return ResultImpl.Ok(val)
|
||||||
end)
|
end) :: Result<T, E>
|
||||||
|
end
|
||||||
|
|
||||||
|
function Result.ok<T, E>(self: Result<T, E>): Option<T>
|
||||||
|
return self:mapOr(OptionImpl.None, function(val: T)
|
||||||
|
return OptionImpl.Some(val)
|
||||||
|
end) :: Option<T>
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue