Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change text detect to check first and last 512 bytes #2310

Merged
merged 5 commits into from
Feb 21, 2024
Merged
Changes from 1 commit
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
15 changes: 13 additions & 2 deletions src/pkg/utils/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,20 @@ func IsTextFile(path string) (bool, error) {
}
defer f.Close() // Make sure to close the file when we're done

// Read the first 512 bytes of the file
// Get file stat
stat, err := f.Stat()
if err != nil {
return false, err
}

// Create 512 byte buffer
data := make([]byte, 512)
n, err := f.Read(data)
WeaponX314 marked this conversation as resolved.
Show resolved Hide resolved

// Clip offset to minimum of 0
offset := max(0, stat.Size()-512)

// Read the last 512 bytes of the file
n, err := f.ReadAt(data, offset)
if err != nil && err != io.EOF {
return false, err
}
Expand Down
Loading