xtractr icon indicating copy to clipboard operation
xtractr copied to clipboard

Filenames appear as garbled text when extracting.

Open Yuelioi opened this issue 5 months ago • 0 comments

I am encountering an issue where the filenames appear garbled when extracted from a compressed archive. This may be due to the filenames being encoded in a different character set. It would be helpful if there were an option to pass an encoding interpreter when extracting the files to ensure the filenames are correctly decoded

maybe we can

// add a function to deal with decode
func (x *XFile)DecodeString( src string) (string, error) {
	reader := transform.NewReader(bytes.NewReader([]byte(src)), x.decoder)
	decodedBytes, err := io.ReadAll(reader)
	if err != nil {
		return "", err
	}
	return string(decodedBytes), nil
}
type XFile struct {
	// Path to archive being extracted.
	FilePath string
	// Folder to extract archive into.
	OutputDir string
	
	// 
	Decoder *encoding.Decoder
}

func writeFile(fpath string, fdata io.Reader, fMode, dMode os.FileMode) (int64, error) {
       fpath,_ = DecodeString(fpath) // add this
	if err := os.MkdirAll(filepath.Dir(fpath), dMode); err != nil {
		return 0, fmt.Errorf("os.MkdirAll: %w", err)
	}
        ...
	return s, nil
}

and so on

Yuelioi avatar Aug 27 '24 22:08 Yuelioi