Why function zip creates empty .zip archive from big sized files?

Viewed 33

I wrote a function that makes a .zip archive from a directory (and subdir-s, files in it)

func ZipDirectory(backupName string) error {
    file, err := os.Create(backupName)
    if err != nil {
        return err
    }
    defer file.Close()

    w := zip.NewWriter(file)
    defer w.Close()

    walker := func(path string, info os.FileInfo, err error) error {
        if err != nil {
            return err
        }
        if info.IsDir() {
            return nil
        }

        file, err := os.Open(path)
        if err != nil {
            return fmt.Errorf("error opening file %q: %w", path, err)
        }
        defer file.Close()

        f, err := w.Create(path)
        if err != nil {
            return fmt.Errorf("error creating file %q: %w", path, err)
        }

        _, err = io.Copy(f, file)
        if err != nil {
            return fmt.Errorf("error copying file %q: %w", path, err)
        }

        return nil
    }
    err = filepath.Walk(config.FilePath, walker)
    if err != nil {
        return err
    }
    return nil
}

but if directory weights more then 3GB it creates empty archive which weights exactly as it should be.

it looks like this:
enter image description here

enter image description here

help, don't understand this mystic result....

1 Answers

Big zip archives shows empty after archivation because you don't have installed software for unzipiing it (like 7Zip) After installation and openning with 7Zip everything works

Related