Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,18 @@ export const filesFilter = (opt: TarOptions, files: string[]) => {
const listFileSync = (opt: TarOptionsSyncFile) => {
const p = new Parser(opt)
const file = opt.file
let fd
let fd: number | undefined
try {
const stat = fs.statSync(file)
const readSize = opt.maxReadSize || 16 * 1024 * 1024
fd = fs.openSync(file, 'r')
const stat: fs.Stats = fs.fstatSync(fd)
const readSize: number = opt.maxReadSize || 16 * 1024 * 1024
if (stat.size < readSize) {
p.end(fs.readFileSync(file))
const buf = Buffer.allocUnsafe(stat.size)
fs.readSync(fd, buf, 0, stat.size, 0)
p.end(buf)
} else {
let pos = 0
const buf = Buffer.allocUnsafe(readSize)
fd = fs.openSync(file, 'r')
while (pos < stat.size) {
const bytesRead = fs.readSync(fd, buf, 0, readSize, pos)
pos += bytesRead
Expand Down