-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add max file size config (#49)
- Loading branch information
1 parent
0224be3
commit a55d14e
Showing
4 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
-- Generated by Twitch viewer AusCryptor using OpanAI ChatGPT | ||
|
||
local parse = {} | ||
|
||
function parse_file_size(sizeStr) | ||
-- Trim the string to avoid whitespace issues | ||
local trimmed = sizeStr:lower():match("^%s*(.-)%s*$") | ||
|
||
-- Match the numeric part and the unit | ||
local num, unit = trimmed:match("^(%d+%.?%d*)%s*([kmgtpi].b?)$") | ||
num = tonumber(num) | ||
|
||
-- Return nil if there is no numeric part or unit | ||
if not num or not unit then return nil end | ||
|
||
-- Define the multipliers for each unit | ||
local multipliers = { | ||
b = 1, | ||
kb = 1024, | ||
kib = 1024, | ||
mb = 1024 ^ 2, | ||
mib = 1024 ^ 2, | ||
gb = 1024 ^ 3, | ||
gib = 1024 ^ 3, | ||
tb = 1024 ^ 4, | ||
tib = 1024 ^ 4, | ||
pb = 1024 ^ 5, | ||
pib = 1024 ^ 5 -- adding petabyte for completeness | ||
} | ||
|
||
-- Calculate the number of bytes | ||
local multiplier = multipliers[unit] | ||
if not multiplier then | ||
return nil | ||
end | ||
|
||
return num * multiplier | ||
end | ||
|
||
parse.file_size = parse_file_size | ||
|
||
return parse |