From c997a0b9ae687d4b3552d264ddb6e241159897f6 Mon Sep 17 00:00:00 2001 From: James Dugan Date: Sat, 20 Apr 2024 16:46:45 -0600 Subject: [PATCH] fix: cat doesn't print extra newline at end of each file --- CHANGELOG.md | 3 +++ nature/commands/cat.lua | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eb5beb..4401297 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # 🎀 Changelog ## Unreleased +### Fixed +- `cat` command no longer prints extra newline at end of each file + ### Added - `cat` command now reads files in chunks, allowing for reading large files diff --git a/nature/commands/cat.lua b/nature/commands/cat.lua index 34ebbb8..a2375e9 100644 --- a/nature/commands/cat.lua +++ b/nature/commands/cat.lua @@ -9,7 +9,7 @@ commander.register('cat', function(args, sinks) usage: cat [file]...]] end - local chunk_size = 2^13 -- 8K buffer size + local chunkSize = 2^13 -- 8K buffer size for _, fName in ipairs(args) do local f = io.open(fName) @@ -20,11 +20,10 @@ usage: cat [file]...]] end while true do - local block = f:read(chunk_size) + local block = f:read(chunkSize) if not block then break end sinks.out:write(block) end - sinks.out:writeln("") ::continue:: end io.flush()