r"""
    Adds the files in `fpath_list` to an zip/tar archive.

    Args:
        archive_fpath (str): path to zipfile to create
        fpath_list (list): path of files to add to the zipfile
        small (bool): if True uses compression but the zipfile will take more
            time to write
        allowZip64 (bool): use if a file is over 2GB
        overwrite (bool):
        verbose (bool):  verbosity flag(default = True)
        common_prefix (bool): (default = False)

    References:
        https://docs.python.org/2/library/zipfile.html

    CommandLine:
        python -m utool.util_grabdata --test-archive_files

    Example:
        >>> # DISABLE_DOCTEST
        >>> # SLOW_DOCTEST
        >>> from utool.util_grabdata import *  # NOQA
        >>> import utool as ut
        >>> archive_fpath = ut.get_app_cache_dir('utool', 'testarchive.zip')
        >>> # remove an existing test archive
        >>> ut.delete(archive_fpath)
        >>> assert not exists(archive_fpath), 'archive should not exist'
        >>> fpath_list = [ut.grab_test_imgpath(key) for key in ut.TESTIMG_URL_DICT]
        >>> small = True
        >>> allowZip64 = False
        >>> overwrite = True
        >>> result = archive_files(archive_fpath, fpath_list, small, allowZip64, overwrite)
        >>> # verify results
        >>> print(result)
        >>> assert exists(archive_fpath), 'archive should exist'

    Ignore:
        # http://superuser.com/questions/281573/best-options-compressing-files-7-zip
        # Create a small 7zip archive
        7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on archive.7z dir1
        7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on ibeis-linux-binary.7z ibeis

        # Create a small zip archive
        7za a -mm=Deflate -mfb=258 -mpass=15 -r ibeis-linux-binary.zip ibeis

def archive_files(archive_fpath, fpath_list, small=True, allowZip64=False,
                  overwrite=False, verbose=True, common_prefix=False):
    r"""
    Adds the files in `fpath_list` to an zip/tar archive.

    Args:
        archive_fpath (str): path to zipfile to create
        fpath_list (list): path of files to add to the zipfile
        small (bool): if True uses compression but the zipfile will take more
            time to write
        allowZip64 (bool): use if a file is over 2GB
        overwrite (bool):
        verbose (bool):  verbosity flag(default = True)
        common_prefix (bool): (default = False)

    References:
        https://docs.python.org/2/library/zipfile.html

    CommandLine:
        python -m utool.util_grabdata --test-archive_files

    Example:
        >>> # DISABLE_DOCTEST
        >>> # SLOW_DOCTEST
        >>> from utool.util_grabdata import *  # NOQA
        >>> import utool as ut
        >>> archive_fpath = ut.get_app_cache_dir('utool', 'testarchive.zip')
        >>> # remove an existing test archive
        >>> ut.delete(archive_fpath)
        >>> assert not exists(archive_fpath), 'archive should not exist'
        >>> fpath_list = [ut.grab_test_imgpath(key) for key in ut.TESTIMG_URL_DICT]
        >>> small = True
        >>> allowZip64 = False
        >>> overwrite = True
        >>> result = archive_files(archive_fpath, fpath_list, small, allowZip64, overwrite)
        >>> # verify results
        >>> print(result)
        >>> assert exists(archive_fpath), 'archive should exist'

    Ignore:
        # http://superuser.com/questions/281573/best-options-compressing-files-7-zip
        # Create a small 7zip archive
        7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on archive.7z dir1
        7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on ibeis-linux-binary.7z ibeis

        # Create a small zip archive
        7za a -mm=Deflate -mfb=258 -mpass=15 -r ibeis-linux-binary.zip ibeis

    """
    import utool as ut
    from os.path import relpath, dirname
    if not overwrite and ut.checkpath(archive_fpath, verbose=True):
        raise AssertionError('cannot overrwite archive_fpath=%r' % (archive_fpath,))
    print('Archiving %d files' % len(fpath_list))
    compression = zipfile.ZIP_DEFLATED if small else zipfile.ZIP_STORED
    if common_prefix:
        # Note: common prefix does not care about file structures
        if isinstance(common_prefix, six.string_types):
            # use given path as base path
            rel_arcpath = common_prefix
        else:
            rel_arcpath = commonprefix(fpath_list)
        rel_arcpath = ut.longest_existing_path(rel_arcpath)
    else:
        rel_arcpath = dirname(archive_fpath)
    with zipfile.ZipFile(archive_fpath, 'w', compression, allowZip64) as myzip:
        for fpath in ut.ProgressIter(fpath_list, lbl='archiving files',
                                     enabled=verbose, adjust=True):
            arcname = relpath(fpath, rel_arcpath)
            myzip.write(fpath, arcname)