From 0a225ac847f3a9bbf521b8ca646bfda41d1bad19 Mon Sep 17 00:00:00 2001 From: James Dugan Date: Thu, 18 Apr 2024 20:30:36 -0600 Subject: [PATCH] feat: Cat implementation now uses chunk reading --- CHANGELOG.md | 4 ++++ nature/commands/cat.lua | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b52101a..6eb5beb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 🎀 Changelog +## Unreleased +### Added +- `cat` command now reads files in chunks, allowing for reading large files + ## [2.2.2] - 2024-04-16 ### Fixed - Line refresh fixes (less flicker) diff --git a/nature/commands/cat.lua b/nature/commands/cat.lua index 06df507..34ebbb8 100644 --- a/nature/commands/cat.lua +++ b/nature/commands/cat.lua @@ -9,6 +9,8 @@ commander.register('cat', function(args, sinks) usage: cat [file]...]] end + local chunk_size = 2^13 -- 8K buffer size + for _, fName in ipairs(args) do local f = io.open(fName) if f == nil then @@ -17,7 +19,12 @@ usage: cat [file]...]] goto continue end - sinks.out:writeln(f:read '*a') + while true do + local block = f:read(chunk_size) + if not block then break end + sinks.out:write(block) + end + sinks.out:writeln("") ::continue:: end io.flush()