Skip to content

Commit

Permalink
feat: cat implementation now uses chunk reading (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdugan6240 authored Apr 20, 2024
1 parent 16b39fe commit aa376f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 🎀 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

## [2.2.2] - 2024-04-16
### Fixed
- Line refresh fixes (less flicker)
Expand Down
8 changes: 7 additions & 1 deletion nature/commands/cat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ commander.register('cat', function(args, sinks)
usage: cat [file]...]]
end

local chunkSize = 2^13 -- 8K buffer size

for _, fName in ipairs(args) do
local f = io.open(fName)
if f == nil then
Expand All @@ -17,7 +19,11 @@ usage: cat [file]...]]
goto continue
end

sinks.out:writeln(f:read '*a')
while true do
local block = f:read(chunkSize)
if not block then break end
sinks.out:write(block)
end
::continue::
end
io.flush()
Expand Down

0 comments on commit aa376f9

Please sign in to comment.