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

Superfile doesn't render small text files #327

Open
jkrshnmenon opened this issue Aug 7, 2024 · 2 comments
Open

Superfile doesn't render small text files #327

jkrshnmenon opened this issue Aug 7, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@jkrshnmenon
Copy link

jkrshnmenon commented Aug 7, 2024

Describe the bug
The function isTextFile in src/internal/string_function.go returns false even if the file contains printable characters only.

To Reproduce
Steps to reproduce the behavior:

  1. Create a file with the command echo "A" > /tmp/test
  2. Use spf to open the /tmp directory and seek to the test file
  3. The pane on the right will show the Unsupported formats error

Expected behavior
A normal rendering of the file contents

System information (please complete the following information):

  • OS: Ubuntu
  • Version 22.04
  • Superfile Version v1.1.3
@jkrshnmenon jkrshnmenon added the bug Something isn't working label Aug 7, 2024
@jkrshnmenon
Copy link
Author

Screenshots
report

Fixed the screenshot

@jkrshnmenon
Copy link
Author

I believe the reason for this behavior is that this line will iterate beyond the contents of the file and stop when it encounters the first NULL byte.

A simple fix could be something like the following:

    fileInfo, err := file.Stat()
    if err != nil {
	return false, err
    }
    
    bufferSize := min(fileInfo.Size(), 1024)

    reader := bufio.NewReader(file)
    buffer := make([]byte, bufferSize)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant