lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


-- preallocate 1Gb
f=io.open("dummy.bin","wb") or error()
f:seek("set",1024*1024*1024-1)
f:write("1")
f:close()

пт, 21 июн. 2019 г. в 21:14, Philippe Verdy <verdy_p@wanadoo.fr>:
>
> May be some native extension can add this functionality to existing file objects (by adding i/o methods, or a way to pass native I/O requests via some escape mechanism that the extension will check itself.
>
> There are other features missing infile I/O, notably the possibility of prealocating empty space (without really having to write it on disk: it can jsut be marked in the filesystem allocation table has being allocated, but also implictly full of zeroes, freeing the OS from having to make physical reads as well, and it is very useful as well for "virtual" files. Another possibility is to virtualize a file's version (with separate commits of sectors/clusters into versioned branches), or the possibility of virtualizing multiple distinct files to share the same physical space by default, also virtualized when one file is written but not the other).
>
> Various filesystems have already implemented these, notably to better support virtual machines with lower cost and improved performance by reduced physical I/O; it is already the case on Linux (with recent versions of Ext4, including for Android devices) and Windows (with NTFS), and most probably as well on MacOS. And any OS that has now support for efficient implementation of virtual machines have added such support in at least one of their supported filesystems, or have added one which can also be used for other applications (including for installing the OS itself and maintaining it securely with "instant snashots").
>
> I wonder why POSIX did not try to extend the minimum set of file I/O API that a decent OS should support (or that can probably be easily emulated by small plugins in the implementation of virtual machines and scripting engines like Lua, even if sometimes it may be much slower than when using the native filesystem support).
>
>
> Le ven. 21 juin 2019 à 01:37, Paul K <paul@zerobrane.com> a écrit :
>>
>> > How to trim existing file from 2Gb to 1Gb using lua io?
>>
>> Lua I/O doesn't provide any function to truncate a file. I supported
>> suggestion to add one. See this thread for a previous discussion on
>> this topic: http://lua.2524044.n2.nabble.com/Function-to-truncate-a-file-td7684482.html
>>
>> If you need a portable solution, you can use Lua/APR
>> (http://peterodding.com/code/lua/apr/docs/#file:truncate) or fs
>> library (https://luapower.com/fs; requires FFI).
>>
>> Paul.
>>
>> On Thu, Jun 20, 2019 at 4:21 PM Sergey Kovalev <kovserg33@gmail.com> wrote:
>> >
>> > How to trim existing file from 2Gb to 1Gb using lua io?
>> >
>>