mirror of
				https://github.com/eworm-de/routeros-scripts.git
				synced 2024-05-11 05:55:19 +00:00 
			
		
		
		
	global-functions: introduce $FetchHuge
This commit is contained in:
		| @@ -4,7 +4,7 @@ RouterOS Scripts | |||||||
| [](https://github.com/eworm-de/routeros-scripts/stargazers) | [](https://github.com/eworm-de/routeros-scripts/stargazers) | ||||||
| [](https://github.com/eworm-de/routeros-scripts/network) | [](https://github.com/eworm-de/routeros-scripts/network) | ||||||
| [](https://github.com/eworm-de/routeros-scripts/watchers) | [](https://github.com/eworm-de/routeros-scripts/watchers) | ||||||
| [](https://mikrotik.com/download/changelogs/) | [](https://mikrotik.com/download/changelogs/) | ||||||
| [](https://t.me/routeros_scripts) | [](https://t.me/routeros_scripts) | ||||||
| [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J) | [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
| #                         Michael Gisbers <michael@gisbers.de> | #                         Michael Gisbers <michael@gisbers.de> | ||||||
| # https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md | # https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md | ||||||
| # | # | ||||||
| # requires RouterOS, version=7.12 | # requires RouterOS, version=7.13 | ||||||
| # | # | ||||||
| # global functions | # global functions | ||||||
| # https://git.eworm.de/cgit/routeros-scripts/about/ | # https://git.eworm.de/cgit/routeros-scripts/about/ | ||||||
| @@ -32,6 +32,7 @@ | |||||||
| :global DownloadPackage; | :global DownloadPackage; | ||||||
| :global EitherOr; | :global EitherOr; | ||||||
| :global EscapeForRegEx; | :global EscapeForRegEx; | ||||||
|  | :global FetchHuge; | ||||||
| :global FetchUserAgentStr; | :global FetchUserAgentStr; | ||||||
| :global FormatLine; | :global FormatLine; | ||||||
| :global FormatMultiLines; | :global FormatMultiLines; | ||||||
| @@ -389,6 +390,42 @@ | |||||||
|   :return $Return; |   :return $Return; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | # fetch huge data to file, read in chunks | ||||||
|  | :set FetchHuge do={ | ||||||
|  |   :local ScriptName [ :tostr $1 ]; | ||||||
|  |   :local Url        [ :tostr $2 ]; | ||||||
|  |  | ||||||
|  |   :global GetRandom20CharAlNum; | ||||||
|  |   :global LogPrint; | ||||||
|  |   :global MkDir; | ||||||
|  |   :global WaitForFile; | ||||||
|  |  | ||||||
|  |   :if ([ $MkDir "tmpfs/" . $ScriptName ] = false) do={ | ||||||
|  |     $LogPrint error $0 ("Failed creating directory!"); | ||||||
|  |     :return false; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   :local FileName ("tmpfs/" . $ScriptName . "/" . $0 . "-" . [ $GetRandom20CharAlNum ]); | ||||||
|  |  | ||||||
|  |   :do { | ||||||
|  |     /tool/fetch check-certificate=yes-without-crl $Url dst-path=$FileName as-value; | ||||||
|  |   } on-error={ | ||||||
|  |     $LogPrint debug $0 ("Failed downloading from: " . $Url); | ||||||
|  |     :return false; | ||||||
|  |   } | ||||||
|  |   $WaitForFile $FileName; | ||||||
|  |  | ||||||
|  |   :local FileSize [ /file/get $FileName size ]; | ||||||
|  |   :local Return ""; | ||||||
|  |   :local VarSize 0; | ||||||
|  |   :while ($VarSize < $FileSize) do={ | ||||||
|  |     :set Return ($Return . ([ /file/read offset=$VarSize chunk-size=32768 file=$FileName as-value ]->"data")); | ||||||
|  |     :set VarSize [ :len $Return ]; | ||||||
|  |   } | ||||||
|  |   /file/remove $FileName; | ||||||
|  |   :return $Return; | ||||||
|  | } | ||||||
|  |  | ||||||
| # generate user agent string for fetch | # generate user agent string for fetch | ||||||
| :set FetchUserAgentStr do={ | :set FetchUserAgentStr do={ | ||||||
|   :local Caller [ :tostr $1 ]; |   :local Caller [ :tostr $1 ]; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user