# Max size of variables still at 4096!? Anwser is NO

**URL:** <https://forum.mikrotik.com/t/max-size-of-variables-still-at-4096-anwser-is-no/168007>\
**Category:** Scripting\
**Created:** [July 12, 2023, 7:07pm UTC](https://forum.mikrotik.com/t/max-size-of-variables-still-at-4096-anwser-is-no/168007 "2023-07-12T19:07:09Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![rextended](https://forum.mikrotik.com/user_avatar/forum.mikrotik.com/rextended/32/67729_2.png) [@rextended](https://forum.mikrotik.com/u/rextended)\
**Post date:** [July 12, 2023, 9:55pm UTC](https://forum.mikrotik.com/t/max-size-of-variables-still-at-4096-anwser-is-no/168007/3 "2023-07-12T21:55:19Z")

</div>

> [@](#):
>
> ```plaintext
> Imported file length 64512 bytes
> 
> ```

Sorry, but the limit from a file are stil lthe same: 64512, what is changed on this?  
(ignoring the WRITING of a file)  
[http://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/1](http://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/1)  
I did not understand (seriously, no joke)…  
  
  
This create on 6.x and on 7.x one variable of 41.943.040B (~40MB)

```plaintext
:global test "0123456789"
:for i from=1 to=22 do={:set test ($test . $test);:put [:len $test]}

```

The limit is the memory on the board,  
and if the variable is more than ~64KB system/script/environment is unusable and winbox on that session crash or say “ **ERROR: action failed** ”  
On router with lower memory @ 40MB **Console has crashed; please log in again.**

I didn’t finish the blacklist import script anymore,  
but through my method it is possible to read pieces of ~64KB,  
combine them all together in a single variable without bothering about the cut pieces between one reading and another,  
and therefore finally process the list.  
  
  
  
Based on my idea of 2 yerars ago:  
[http://forum.mikrotik.com/t/how-to-download-only-one-piece-of-file-at-a-time-with-tool-fetch-and-put-it-inside-a-variable/151020/1](http://forum.mikrotik.com/t/how-to-download-only-one-piece-of-file-at-a-time-with-tool-fetch-and-put-it-inside-a-variable/151020/1)  
Simply do that…  
:global thefile “”  
{  
:local url “[https://www.iwik.org/ipcountry/US.cidr](https://www.iwik.org/ipcountry/US.cidr)”  
:local filesize ([/tool fetch url=$url as-value output=none]-\>“downloaded”)  
:local maxsize 64512 ; # is the maximum supported readable size of a block from a file  
:local start 0  
:local end ($maxsize - 1)  
:local partnumber ($filesize / ($maxsize / 1024))  
:local reminder ($filesize % ($maxsize / 1024))  
:if ($reminder \> 0) do={ :set partnumber ($partnumber + 1) }  
:for x from=1 to=$partnumber step=1 do={  
:set thefile ($thefile . ([/tool fetch url=$url http-header-field=“Range: bytes=$start-$end” as-value output=user]-\>“data”))  
:set start ($start + $maxsize)  
:set end ($end + $maxsize)  
}  
}  
:put [:len $thefile]  
…for have one unique file on memory of (at the moment I write) 1.031.093B (~1MB)  
  
  
And for save back the file after the variable (file in memory) is modified?

```plaintext
:execute ":put \$thefile" file=newfile.txt

```

But really the file is dirty because “put” add everytime 2Bytes (\r\n) at the end  
  
  
  
:global thefile “”  
{  
:local url (“https://” . “view.sentinel.turris.cz/greylist-data/greylist-latest.csv”) ; # splitted just to not let the forum alter the url  
:local filesize ([/tool fetch url=$url as-value output=none]-\>“downloaded”)  
:local maxsize 64512 ; # is the maximum supported readable size of a block from a file  
:local start 0  
:local end ($maxsize - 1)  
:local partnumber ($filesize / ($maxsize / 1024))  
:local reminder ($filesize % ($maxsize / 1024))  
:if ($reminder \> 0) do={ :set partnumber ($partnumber + 1) }  
:for x from=1 to=$partnumber step=1 do={  
:set thefile ($thefile . ([/tool fetch url=$url http-header-field=“Range: bytes=$start-$end” as-value output=user]-\>“data”))  
:set start ($start + $maxsize)  
:set end ($end + $maxsize)  
}  
}  
:put [:len $thefile]  
302116 = ~300KB (at the moment I write and test the script)

---

_[View the full topic](https://forum.mikrotik.com/t/max-size-of-variables-still-at-4096-anwser-is-no/168007)._
