archive
archive copied to clipboard
Fails to import kmz file created with archive to Google Maps
Steps to reproduce
Execute dart below with test.zip
import 'dart:io';
import 'package:archive/archive_io.dart';
void main() {
// Read the Zip file from disk.
final bytes = File('test.zip').readAsBytesSync();
// Decode the Zip file
final archive = ZipDecoder().decodeBytes(bytes);
// Extract the contents of the Zip archive to disk.
for (final file in archive) {
final filename = file.name;
if (file.isFile) {
final data = file.content as List<int>;
File('out/' + filename)
..createSync(recursive: true)
..writeAsBytesSync(data);
} else {
Directory('out/' + filename).create(recursive: true);
}
}
// Zip a directory to out.zip using the zipDirectory convenience method
var encoder = ZipFileEncoder();
encoder.zipDirectory(Directory('out'), filename: 'out.kmz');
}
Manually create zip with
cd out && zip -r ../out2.kmz * && cd ..
Create a new Google map in My Maps
Import out.kmz file created with archive into layer - Fails
Import out2.kmz file created manually into layer - Succeeds
Added screenshot below. Difficult to debug on Google Maps as there is no error log produced.
Noticed these differences with zipinfo
- archive zip uses "2.0 fat" and compresses "icons/" as file "rw"
- manual zip uses "3.0 unx" and compresses "icons/" as directory "drwx".
zipinfo out.kmz
Archive: out.kmz
Zip file size: 1287 bytes, number of entries: 3
-rw-r--r-- 2.0 fat 685 b- defN 23-Jan-27 07:38 doc.kml
-rw---- 2.0 fat 0 b- defN 23-Jan-27 07:38 icons/
-rw-r--r-- 2.0 fat 815 b- defN 23-Jan-27 07:38 icons/place-red.png
3 files, 1500 bytes uncompressed, 973 bytes compressed: 35.1%
zipinfo out2.kmz
Archive: out2.kmz
Zip file size: 1431 bytes, number of entries: 3
-rw-r--r-- 3.0 unx 685 tx defN 23-Jan-27 07:38 doc.kml
drwxr-xr-x 3.0 unx 0 bx stor 23-Jan-27 07:38 icons/
-rw-r--r-- 3.0 unx 815 bx defN 23-Jan-27 07:38 icons/place-red.png
3 files, 1500 bytes uncompressed, 961 bytes compressed: 35.9%
Don't think it's an issue with the format type "2.0 fat". Running the following forces to fat. Import into Google Maps is successful (though png is renamed so creates generic marker instead). Perhaps issue is that archive does not create "icons/" as directory.
cd out && zip -k -r ../out2.kmz * && cd ..
zipinfo out2.kmz
Archive: out2.kmz
Zip file size: 1429 bytes, number of entries: 3
-rw---- 2.0 fat 685 tx defN 23-Jan-27 07:38 DOC.KML
drwx--- 2.0 fat 0 bx stor 23-Jan-27 07:38 ICONS/
-rw---- 2.0 fat 815 bx defN 23-Jan-27 07:38 ICONS/PLACE-RE.PNG
3 files, 1500 bytes uncompressed, 961 bytes compressed: 35.9%
Tried using flutter_archive which successfully imports into Google Maps.
zipinfo out3.kmz
Archive: out3.kmz
Zip file size: 1325 bytes, number of entries: 3
-rw---- 2.0 fat 684 bl defN 23-Jan-31 09:14 doc.kml
-rw---- 2.0 fat 0 bl defN 23-Jan-31 09:14 icons/
-rw---- 2.0 fat 815 bl defN 23-Jan-31 09:14 icons/place-red.png
3 files, 1499 bytes uncompressed, 963 bytes compressed: 35.8%
Compared to archive which fails
zipinfo out.kmz
Archive: out.kmz
Zip file size: 1287 bytes, number of entries: 3
-rw---- 2.0 fat 0 b- defN 23-Jan-31 09:17 icons/
-rw-r--r-- 2.0 fat 815 b- defN 23-Jan-31 09:17 icons/place-red.png
-rw-r--r-- 2.0 fat 685 b- defN 23-Jan-31 09:17 doc.kml
3 files, 1500 bytes uncompressed, 973 bytes compressed: 35.1%
So really not sure why it only fails for archive. Submitted feedback request to Google about issue. As a workaround will use flutter_archive for now.
I haven't had a chance to look into the file permissions yet. I will once work settles down some.