yorukot / superfile

Pretty fancy and modern terminal file manager
https://superfile.netlify.app
MIT License
5.85k stars 126 forks source link

Superfile doesn't render small text files #327

Open jkrshnmenon opened 2 months ago

jkrshnmenon commented 2 months ago

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):

jkrshnmenon commented 2 months ago

Screenshots report

Fixed the screenshot

jkrshnmenon commented 2 months ago

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)