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

Can not find extracted file anywhere #356

Closed
ijkzen opened this issue Oct 27, 2022 · 1 comment
Closed

Can not find extracted file anywhere #356

ijkzen opened this issue Oct 27, 2022 · 1 comment

Comments

@ijkzen
Copy link

ijkzen commented Oct 27, 2022

What version of the package or command are you using?

v4.0.0-alpha.7

What are you trying to do?

I'm from v3, and now using v4.
but can not find api like v3 in v4:

archiver.Unarchive("test.tar.gz", "test")

so I write code following using v4:

func Unzip(src string, dest string) error {
	if exist, _ := initial.IsFileExist(dest); !exist {
		os.MkdirAll(dest, os.ModePerm)
	}

	supportFormat := []string{
		"rar",
		"zip",
		"tar",
		"gz",
		"bz2",
		"7z",
	}

	var isSupported = false
	for _, format := range supportFormat {
		if strings.HasSuffix(src, format) {
			isSupported = true
			break
		}
	}

	if !isSupported {
		return fmt.Errorf("%s is not supported", src)
	} else {
		reader, err := os.Open(src)
		if err != nil {
			return err
		}
		format, input, err := archiver.Identify(src, reader)
		if err != nil {
			return err
		} else {
			if ex, ok := format.(archiver.Extractor); ok {
				ex.Extract(context.Background(), input, nil, func(ctx context.Context, f archiver.File) error {
					initial.SugarLogger.Infof("handle %s", f.Name())
					return nil
				})
			}

			return nil
		}
	}
}

but I do not find extracted file anywhere.

What did you expect to happen, and what actually happened instead?

I want to has api like v3 in v4 to extract file easily.

How do you think this should be fixed?

fix will be better

Bonus: What do you use archiver for, and do you find it useful?

I download some subtitle archive file from network, and extract them to save database.

@mholt
Copy link
Owner

mholt commented Oct 27, 2022

Archiver v4 doesn't write to the file system (see #311) - that's up to you, if you want to do that. Archiver v4 just gives you the streams you can use to do whatever you want with them.

@mholt mholt closed this as not planned Won't fix, can't repro, duplicate, stale Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants