diff --git a/archivex.go b/archivex.go
index <HASH>..<HASH> 100644
--- a/archivex.go
+++ b/archivex.go
@@ -296,18 +296,18 @@ func (t *TarFile) AddAll(dir string, includeCurrentFolder bool) error {
 
 // Close the file Tar
 func (t *TarFile) Close() error {
+	err := t.Writer.Close()
+	if err != nil {
+		return err
+	}
+
 	if t.Compressed {
-		err := t.GzWriter.Close()
+		err = t.GzWriter.Close()
 		if err != nil {
 			return err
 		}
 	}
 
-	err := t.Writer.Close()
-	if err != nil {
-		return err
-	}
-
 	return err
 }
the file was being closed in the wrong order