Skip to content

Filenames appear as garbled text when extracting. #72

@Yuelioi

Description

@Yuelioi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions