Giter Club home page Giter Club logo

grunt-contrib-compress's Introduction

grunt-contrib-compress v2.0.0 Build Status

Compress files and folders

Getting Started

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-contrib-compress --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-contrib-compress');

This plugin was designed to work with Grunt >= 0.4.x. If you're still using grunt v0.3.x it's strongly recommended that you upgrade, but in case you can't please use v0.3.2.

Compress task

Run this task with the grunt compress command.

Task targets, files and options may be specified according to the grunt Configuring tasks guide.

Node Libraries Used: archiver (for zip/tar) zlib (for gzip).

Options

archive

Type: String or Function
Modes: zip tar

This is used to define where to output the archive. Each target can only have one output file. If the type is a Function it must return a String.

This option is only appropriate for many-files-to-one compression modes like zip and tar. For gzip for example, please use grunt's standard src/dest specifications.

mode

Type: String

This is used to define which mode to use, currently supports gzip, deflate, deflateRaw, tar, tgz (tar gzip),zip and brotli.

Automatically detected per dest:src pair, but can be overridden per target if desired.

level

Type: Integer
Modes: zip gzip
Default: 1

Sets the level of archive compression.

brotli

Configure brotli compression settings:

Type: Object
Default:

{
    [zlib.constants.BROTLI_PARAM_MODE]: 0,
    [zlib.constants.BROTLI_PARAM_QUALITY]: 11,
    [zlib.constants.BROTLI_PARAM_LGWIN]: 22,
    [zlib.constants.BROTLI_PARAM_LGBLOCK]: 0
}

Do not forget require zlib for zlib.constants, example:

const zlib = require('zlib');
mode

Type: Integer

  • 0: generic mode
  • 1: text mode
  • 2: font mode

Default: 0

quality

Controls the compression-speed vs compression-density tradeoffs. The higher the quality, the slower the compression. Range is 0 to 11.

Type: Integer
Default: 11

lgwin

Base 2 logarithm of the sliding window size. Range is 10 to 24.

Type: Integer
Default: 22

lgblock

Base 2 logarithm of the maximum input block size. Range is 16 to 24. If set to 0, the value will be set based on the quality.

Type: Integer
Default: 0

pretty

Type: Boolean
Default: false

Pretty print file sizes when logging.

createEmptyArchive

Type: Boolean
Default: true

This can be used when you don't want to get an empty archive as a result, if there are no files at the specified paths.

It may be useful, if you don't clearly know if files exist and you don't need an empty archive as a result.

File Data

The following additional keys may be passed as part of a dest:src pair when using an Archiver-backed format. All keys can be defined as a Function that receives the file name and returns in the type specified below.

date

Type: Date
Modes: zip tar tgz

Sets the file date.

mode

Type: Integer
Modes: zip tar tgz

Sets the file permissions.

store

Type: Boolean
Default: false

If true, file contents will be archived without compression.

comment

Type: String
Modes: zip

Sets the file comment.

gid

Type: Integer
Modes: tar tgz

Sets the group of the file in the archive

uid

Type: Integer
Modes: tar tgz

Sets the user of the file in the archive

Usage Examples

// make a zipfile
compress: {
  main: {
    options: {
      archive: 'archive.zip'
    },
    files: [
      {src: ['path/*'], dest: 'internal_folder/', filter: 'isFile'}, // includes files in path
      {src: ['path/**'], dest: 'internal_folder2/'}, // includes files in path and its subdirs
      {expand: true, cwd: 'path/', src: ['**'], dest: 'internal_folder3/'}, // makes all src relative to cwd
      {flatten: true, src: ['path/**'], dest: 'internal_folder4/', filter: 'isFile'} // flattens results to a single level
    ]
  }
}
// gzip assets 1-to-1 for production
compress: {
  main: {
    options: {
      mode: 'gzip'
    },
    expand: true,
    cwd: 'assets/',
    src: ['**/*'],
    dest: 'public/'
  }
}
// compress a file to a different location than its source
// example compresses path/the_file to /the_file inside archive.zip
compress: {
  main: {
    options: {
      archive: 'archive.zip'
    },
    files: [{
      expand: true,
      cwd: 'path/',
      src: ['the_file'],
      dest: '/'
    }]
  }
},
// use custom extension for the output file
compress: {
  main: {
    options: {
      mode: 'gzip'
    },
    // Each of the files in the src/ folder will be output to
    // the dist/ folder each with the extension .gz.js
    files: [{
      expand: true,
      src: ['src/*.js'],
      dest: 'dist/',
      ext: '.gz.js'
    }]
  }
}
// use a function to return the output file
compress: {
  main: {
    options: {
      archive: function () {
        // The global value git.tag is set by another task
        return git.tag + '.zip'
      }
    },
    files: [{
      expand: true,
      src: ['src/*.js'],
      dest: 'dist/'
    }]
  }
}
// brotlify assets 1-to-1 for production using default options
compress: {
  main: {
    options: {
      mode: 'brotli'
    },
    expand: true,
    cwd: 'assets/',
    src: ['**/*.js'],
    dest: 'public/',
    extDot: 'last',
    ext: '.js.br'
  }
}
// brotlify assets 1-to-1 for production specifying text mode
// and using default options otherwise
compress: {
  main: {
    options: {
      mode: 'brotli',
      brotli: {
        mode: 1
      }
    },
    expand: true,
    cwd: 'assets/',
    src: ['**/*.js'],
    dest: 'public/',
    extDot: 'last',
    ext: '.js.br'
  }
}

Release History

  • 2020-12-12   v2.0.0   Remove iltorb dependency, now uses zlib brotli features. Requires node >=10.16. Dependency and test updates.
  • 2019-10-21   v1.6.0   Update iltorb dependency
  • 2018-04-24   v1.5.0   Update to node 4 as minimum version update tar to 4.4.8
  • 2017-05-20   v1.4.3   Update pretty-bytes to v4.0.2. Add option to not to create empty archive.
  • 2017-05-20   v1.4.2   Update archiver to v1.3.0.
  • 2017-01-20   v1.4.1   Make brotli support optional.
  • 2017-01-18   v1.4.0   Add support for brotli.
  • 2016-05-24   v1.3.0   Update archiver to v1.0. Fix node 6 support.
  • 2016-03-24   v1.2.0   Dependency update.
  • 2016-03-08   v1.1.1   Fix verbose output.
  • 2016-03-04   v1.1.0   Add ability to replace file in the same location.
  • 2016-02-15   v1.0.0   Update archiver, chalk and pretty-bytes.
  • 2015-10-23   v0.14.0   Change to verbose output. Dependency updates archiver 0.16.
  • 2014-12-25   v0.13.0   Update archiver to v0.13. Small fixes.
  • 2014-09-23   v0.12.0   Output update. Prevent zipping dot files and allow for forcing through fail.warn within loop.
  • 2014-08-26   v0.11.0   Update archiver to v0.11.0.
  • 2014-07-14   v0.10.0   Don't apply extensions automatically (use ext or rename).
  • 2014-05-20   v0.9.1   Allow directories to pass-through to archiver via filter.
  • 2014-05-20   v0.9.0   Update archiver to v0.9.0.
  • 2014-04-09   v0.8.0   Update archiver to v0.8.0.
  • 2014-02-17   v0.7.0   Update archiver to v0.6.0.
  • 2014-01-12   v0.6.0   Update archiver to v0.5.0.
  • 2013-11-27   v0.5.3   Allow archive option to be a function.
  • 2013-06-03   v0.5.2   Allow custom extensions using the ext option.
  • 2013-05-28   v0.5.1   Avoid gzip on folders.
  • 2013-04-23   v0.5.0   Add support for deflate and deflateRaw.
  • 2013-04-15   v0.4.10   Fix issue where task finished before all data was compressed.
  • 2013-04-09   v0.4.9   Bump Archiver version.
  • 2013-04-07   v0.4.8   Open streams lazily to avoid too many open files.
  • 2013-04-01   v0.4.7   Pipe gzip to fix gzip issues. Add tests that undo compressed files to test.
  • 2013-03-25   v0.4.6   Fix Node.js v0.8 compatibility issue with gzip.
  • 2013-03-20   v0.4.5   Update to archiver 0.4.1 Fix issue with gzip failing intermittently.
  • 2013-03-19   v0.4.4   Fixes for Node.js v0.10. Explicitly call grunt.file methods with map and filter.
  • 2013-03-14   v0.4.3   Fix for gzip; continue iteration on returning early.
  • 2013-03-13   v0.4.2   Refactor task like other contrib tasks. Fix gzip of multiple files. Remove unused dependencies.
  • 2013-02-22   v0.4.1   Pretty print compressed sizes. Logging each addition to a compressed file now only happens in verbose mode.
  • 2013-02-15   v0.4.0   First official release for Grunt 0.4.0.
  • 2013-01-23   v0.4.0rc7   Updating grunt/gruntplugin dependencies to rc7. Changing in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions.
  • 2013-01-14   v0.4.0rc5   Updating to work with grunt v0.4.0rc5. Conversion to grunt v0.4 conventions. Replace basePath with cwd.
  • 2012-10-12   v0.3.2   Rename grunt-contrib-lib dep to grunt-lib-contrib.
  • 2012-10-09   v0.3.1   Replace zipstream package with archiver.
  • 2012-09-24   v0.3.0   General cleanup. Options no longer accepted from global config key.
  • 2012-09-18   v0.2.2   Test refactoring. No valid source check. Automatic mode detection.
  • 2012-09-10   v0.2.0   Refactored from grunt-contrib into individual repo.

Task submitted by Chris Talkington

This file was generated on Sat Dec 12 2020 14:15:27.

grunt-contrib-compress's People

Contributors

awaterma avatar caseyjhol avatar ctalkington avatar cumpsd avatar daemonl avatar davglass avatar dependabot[bot] avatar derekcicerone avatar eschwartz avatar hkdobrev avatar jacek-pulit avatar jney avatar jpommerening avatar jrcryer avatar netpro2k avatar pdehaan avatar philippsimon avatar phrred avatar radkodinev avatar richmarr avatar shama avatar sharikovvladislav avatar sindresorhus avatar swatto avatar tandrewnichols avatar tomgault avatar unbalanced avatar vladikoff avatar weigo avatar xhmikosr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-contrib-compress's Issues

dest is ignored when archive type is zip

In the examples you provide, a dest option is set for each file:

// make a zipfile
compress: {
  main: {
    options: {
      archive: 'archive.zip'
    },
    files: [
      {src: ['path/*'], dest: 'internal_folder/', filter: 'isFile'}, // includes files in path
      {src: ['path/**'], dest: 'internal_folder2/'}, // includes files in path and its subdirs
      {expand: true, cwd: 'path/', src: ['**'], dest: 'internal_folder3/'}, // makes all src relative to cwd
      {flatten: true, src: ['path/**'], dest: 'internal_folder4/', filter: 'isFile'} // flattens results to a single level
    ]
  }
}

However, setting dest has absolutely no effect.
If one wants to compress the contents of target/ to target/<%= pkg. name %> the path has to be defined in archive rather than dest.

Working configuration:

config.compress = {
    dist: {
        options: {
            archive: "target/<%= pkg.name %>.zip"
        },
        files: [
            {
                src: ["target/<%= pkg.name %>/**"]
            }
        ]
    }
};

Get rid of basedir

Is there a way to get rid of the basedir? When I use

 files: [
                    {
                        src: ['dest/**'], dest: '', filter: 'isFile'
                    },
                ]

I get an archive with a folder dest, but I just want its contents without the containing folder.

[osx] zip mode?

'zip' mode on OSX seems to be creating a bad zip file.
I am able to unzip it using the native 'unzip', however

unzip -t app.nw >/dev/null
shows errors:

error: invalid compressed data to inflate
file #2956: bad zipfile offset (local header sig): 17794973 ...
(a bunch of theses)

i am using this with node-webkit and, as a result, node-webkit is not able to read the file correctly.

Throwing Error, Not generating ZIP file

Here is my configuration:

compress: {
  main: {
    options: {
      archive: 'archive.zip',
      mode: 'zip'
    },
    files: [
      {
        src: 'dist/**',
        dest: 'build/'
      }
    ]
  }
}

When I run this target I get the following errors:

stream.js:81
      throw er; // Unhandled stream error in pipe.
            ^
Error: ENOENT, open 'build/'

The build/ folder doesn't exist yet, but even when I try and existing directory I get the same error. A folder is created on the root named zip_1360244167121

I'm using

  • Grunt v0.3.17
  • grunt-contrib v0.3.0
  • grunt-contrib-compress v0.3.3

"Unable to read ..." on windows

Hi,

I'm working on setting up my build with grunt and wanted now to compress the build folder to deploy it on a production machine. I'm currently using grunt 0.3.17, node 0.8.14 and grunt-contrib-compress 0.3.2

My compress target looks like this:

compress: {
            gzip: {
                files: {
                    'build.gz':'target/**'
                }
            }
        },

When I'm trying to run that, I get this error message:

c:\Users\mzrinck\Documents\grunt\hwa-mobile>grunt.cmd compress
Running "compress:gzip" (compress) task
<WARN> Unable to read "target/HWA-Mobile-0.0.1/css/jquery.mobile.css,target/HWA-Mobile-0.0.1/images/ajax-loader.gif,target/HWA-Mobile-0.0.1/images/aja
x-loader.png,target/HWA-Mobile-0.0.1/images/icons-18-black.png,target/HWA-Mobile-0.0.1/images/icons-18-white.png,target/HWA-Mobile-0.0.1/images/icons-
36-black.png,target/HWA-Mobile-0.0.1/images/icons-36-white.png,target/HWA-Mobile-0.0.1/index.html,target/HWA-Mobile-0.0.1/js/main.js,target/HWA-Mobile
-0.0.1/partials/auftraggeber.html,target/HWA-Mobile-0.0.1/partials/auftragsDetail.html,target/HWA-Mobile-0.0.1/partials/auftragsListe.html,target/HWA-
Mobile-0.0.1/partials/login.html" file (Error code: ENOENT). Use --force to continue. </WARN>

Basically, it complains about that it can't read ALL files in target folder. Whats happening here?

Mode null not supported

I am trying to use the compress task from the grunt-contrib, I have these lines in my grunt.js and when I run the grunt compress command, I get Mode null not supported ? Any idea?

compress: {
      zip:{
        files: {
          "sitecore.zip": "css/sitecore-speak.css"
        }
      }
    }

For info, I am on windows 7 running the node version v0.8.8

Preserve original dotted parts of filename when adding custom extension

If I set up a task like this:

compress: {
    js: {
        options: {
            mode: "gzip"
        },
        files: [
            {
                expand: true,
                src: path.join(__dirname,"js","*.js"),
                ext: ".js.gz"
            }
        ]
    }
}

This works fine unless I have compound dotted file-names, such as:

js/foo.bar.js
js/foo.bar.bam.js

What I get created is a single js/foo.js.gz which both of those files seem to target, thus the subsequent overwrites the previous.

What I'd like is for a way to specify that the file-extension of a source filename is ".js", and I want only THAT extension replaced by the ".js.gz" in the target file, instead of treating ".bar.js" and "bar.bam.js" as the extensions in the source filenames to be replaced.

Is this possible already and I'm not aware?


I looked through the code to try and see if there was an easy fix, but I was a little confused by how it works and how it identifies the extensions.

I was thinking maybe something like this could work:

{
    expand: true,
    src: path.join(__dirname,"js","*.js"),
    orig_ext: ".js",
    ext: ".js.gz"
}

Is that workable? If so, I'd be happy to try (with some assistance/hints) to submit a patch for it.

compression skipping subdirs in windows

Say you have this directory structure:
build/ --tests/ --docs/ --file1 --file2 --etc
And this config:

compress: {
  zip: {
    files: {
      "build.zip": "build/**"
    }
  }
}

In mac/linux the build.zip that gets created will contain the tests/ and docs/ directories, but on Windows they don't show up.

options.archive ignored when mode is gzip

We just upgraded to the newest version of grunt-contrib-compress and noticed that this is no longer working:

compress: {
    tar: {
        options: {
            mode: 'tar',
            archive: 'temp/dist.tar'
        },
        files: [
            { src: ['dist/**/*'], filter: 'isFile' }
        ]
    },
    gzip: {
        options: {
            mode: 'gzip',
            archive: 'dist.tar.gz'
        },
        files: [
            { src: ['temp/dist.tar'] }
        ]
    }
}

Instead, we have to do:

    gzip: {
        options: {
            mode: 'gzip'
        },
        files: [
            { src: ['temp/dist.tar'], dest: 'dist.tar.gz' }
        ]
    }

This works but doesn't really match compress' documentation and is inconsistent with tar's syntax.

Warning: Arguments to path.join must be strings Use --force to continue.

I am using the following:

grunt 0.4.1
grunt-contrib-compress 0.4.3
nodejs 0.10.0
Ubuntu 12.10

Here's what I have in my grunt file:

compress: {

      package: {
        options: {
          archive: "test.zip"
        },

        files: [
          {src: ['**'], dest: 'internal_folder/'}
       ]

      }
    }

When I run grunt compress, I get the following error:

Options: archive="test.zip", mode="zip", level=1
Warning: Arguments to path.join must be strings Use --force to continue.

Aborted due to warnings.

Incorrect handling of dotfiles with default basePath

When the basePath is left to its default, any dotfiles will be compressed without the leading dot. E.g ".script.js" will become "script.js" inside the archive.

As far as I can tell, this is because of the strRight call in compress.js:128.

This can be worked around by passing any string as basePath, as long as it isn't the prefix of any file.

Tar directory depth

Hi,

I'm trying to create a tarball of a src tree using this grunt plugin.

My config looks something like:
compress: {
main: {
options: {
archive: 'archive.tar',
mode: 'tar'
},
files: [
{expand: true, cwd: 'build/tar/', src: ['**'], dest: '/project/'}
]
}
}

And the tar is successfully created, but when I list the files with tar -tf archive.tar I get the following errors that look like:

:Archive contains 0' where numeric mode_t value expected tar: Archive contains0' where numeric mode_t value expected
tar: Exiting with failure status due to previous errors

After some experimentation it seems that it is related to the max depth of the tar contents, if they are more than 12 levels deep I get the errors, less and I don't.

The tar file does seem to be extractable despite the errors, although I haven't exhaustively checked all the files are present.

Any ideas on the cause would be much appreciated. Perhaps this is better asked in the node-archiver project?

Thanks!

Adding expand to list of files still produces a top level folder

compress:{
      package:{
        options:{
          archive:'package.zip'
        },
        files:[
          {cwd:'package/',src:['**'],dest:'lesson/',expand:true},
          {src:['plugins/**'],dest:'plugins/',expand: true},
          {src:['viewer/**'],dest:'viewer/',expand: true},
          {src:['imsmanifest.xml'],expand: true}
        ]
      }
    }

Doing this still creates a top level 'package' folder when unzipping. How can I just have the folders/files I require at the top level?

Thanks

TypeError: path must be a string

Hi,

I am using grunt v0.3.17 with grunt-contrib-compress v0.3.3.

My configuration inside grunt.js looks like:

compress: {
    partner: {
        options: {
            archive: 'partner.zip',
            mode: 'zip'
        },
        files: [
            {
                src: ['partner/**']
            }
        ]
    }
}

I just want to create a partner.zip file with the content of partner/ folder but I get the error:

TypeError: path must be a string
    at Object.fs.open (fs.js:330:11)
...

Turns out that if I don't specify mode: 'zip' the error is:

Running "compress:partner" (compress) task
<WARN> Mode  not supported. Use --force to continue. </WARN>

Aborted due to warnings.

And if I try to add to specify a dest property the error becomes:

stream.js:81
      throw er; // Unhandled stream error in pipe.
            ^
Error: ENOENT, open ''

What's going on? :(

the dest attribute doesn't work

the compress task defined:

// make a zipfile
        compress: {
            main: {
                options: {
                    archive: 'archive.zip'
                },
                files: [{
                        src: ['../day_320x50/**/*'],
                        dest: '../day_320x50/',
                        filter: 'isFile'
                    }]
            }
        }

the archive.zip will create in the folder where the gruntfile.js is, not the dest defined.
And when I add mode to options, the output likes :

D:\IIS_Test\compress>grunt compress
Running "compress:main" (compress) task
Created ../day_320x50/.gz (34065 bytes)
Created ../day_320x50/.gz (609 bytes)
Created ../day_320x50/.gz (583 bytes)
Created ../day_320x50/.gz (2761 bytes)
Created ../day_320x50/.gz (287 bytes)
Created ../day_320x50/.gz (2940 bytes)
Created ../day_320x50/.gz (2030 bytes)
Created ../day_320x50/.gz (134 bytes)
Created ../day_320x50/.gz (9595 bytes)
Created ../day_320x50/.gz (2648 bytes)
Created ../day_320x50/.gz (1914 bytes)
Created ../day_320x50/.gz (249 bytes)
Created ../day_320x50/.gz (187 bytes)
Created ../day_320x50/.gz (768 bytes)
Created ../day_320x50/.gz (633 bytes)
Created ../day_320x50/.gz (316 bytes)
Created ../day_320x50/.gz (369 bytes)
Created ../day_320x50/.gz (740 bytes)
Created ../day_320x50/.gz (363 bytes)
Created ../day_320x50/.gz (271 bytes)
Created ../day_320x50/.gz (2199 bytes)
Created ../day_320x50/.gz (868 bytes)
Created ../day_320x50/.gz (2420 bytes)
Created ../day_320x50/.gz (1024 bytes)

Done, without errors.
···
What is the reason???

Compressing several files

How can this be used to recursively compress all files in a directory?

For example, I want to generate compressed versions of all my assets along side their uncompressed version.

Thanks,
Evan

Is it possible to replace the file in the same location?

This is more convenient, as I've already built my css and js package to a dist folder using other steps in the build chain.

Is it supposed to be possible to do a configuration like this in a way that replaces the existing file? (instead of adding the .gz extension)

This method adds .gz as a sibling:

    compress:
      options: pretty: true
      mainPackages:
        files: [
          "<%= grunt.option('target') %>all-min.css": "<%= grunt.option('target') %>/all-min.css"
          "<%= grunt.option('target') %>all-min.js": "<%= grunt.option('target') %>/all-min.js"
        ]

This method creates a corrupted file 20 bytes in length:

    compress:
      options: pretty: true
      mainPackages:
        expand: true
        cwd: "<%= grunt.option('target') %>"
        src: '**/{<%= cfg.minName %>.css,core/main.js}'
        dest: "<%= grunt.option('target') %>"
        ext: ''

From grunt 0.30 to 0.40, flatten not working?

I'm trying to get my project to use grunt 0.40 and everything seems to be working fine so far except the compress task. This is what I have now that works:

compress: {
  options: {
    flatten: true
  },
  dist: {
    files: {
      'zip/jquery.idealforms.zip': [
        'css/jquery.idealforms.min.css',
        'js/min/jquery.idealforms.min.js',
        'less/**/*.png',
        'less/**/*.gif',
        'zip/readme.txt'
      ]
    }
  },
},

And this is what I tried for grunt 0.40, but flatten doesn't work:

compress: {
  options: {
    archive: 'zip/jquery.idealforms.zip'
  },
  dist: {
    files: [{
      flatten: true,
      src: [
        'css/jquery.idealforms.min.css',
        'js/min/jquery.idealforms.min.js',
        'less/**/*.png',
        'less/**/*.gif',
        'zip/readme.txt'
      ]
    }]
  }
},

It just won't flatten the result like the previous code did. Am I missing something?

Ability to add a prefix directory

It would be really nice if we can add a prefix option which works in a similar way to the prefix option in Ant. So it creates a top level directory inside the zip.

I haven't looked at the code in detail, so not sure if this just needs a change in here or ZipStream.

Thanks (and thanks for the other grunt-contrib tasks - very handy :)

Fatal error: Object #<Gzip> has no method 'read'

Hi! I've just updated grunt-contrib and here is the error message I'm getting now:

Reading distribution-20130322112301.tar.gz...OK Fatal error: Object #<Gzip> has no method 'read'�

It appears at the very end of the task, apparently, right after all the traces like:

Archiving distribution/... -> ...

Does it ring a bell to someone?

I'm running [email protected] & [email protected].

Broken zip file created

I am using

nodejs 0.10.0
grunt 0.4.1
grunt-contrib-compress 0.4.4
Ubuntu 12.10

I have a project that looks like this:

/my-project
   /some-folder
      /somefile.png
      /somefile2.png
   /src
     /somefolder
     gruntfile.js
     package.json

In my gruntfile, I have the following:

compress: {
      build: {
        options: {
          archive: "build.zip"
        },

        files: [
           {
             cwd: '../',
             expand: true,     // Enable dynamic expansion.
             src: ['**', '!src/**'], // Actual pattern(s) to match.
             dest: 'test/',   // Destination path prefix.
            },
       ]
      }
    },

I then go into /src and ran grunt build.

The build.zip file is then created in /my-project.

The problem is that the generated zip appears to be broken. On my Ubuntu machine, it says there is an error loading the archive. On my windows machine, winzip say it is not a valid archive.

Add "comment" option

I need to add a comment on a zip, so I've checked the Archiver module and they provide this feature.

What do you think about adding it?

Create ZIP file without root folder

I want to create a ZIP-file from all the files in a folder called 'dist', but without them being wrapped in a folder (by default with the same name as the ZIP).

If I do it in the following way:

compress : {
    main : {
        options : {
            archive : "dist/bsd-client.zip"
        },

        files : [
            { src : "*", cwd : "dist/" }
        ]
    }
}

I get the desired effect, but I only get some files in the ZIP-file (because it does not include folders and their subfolders).

Example output unzipped file:

index.html

If I replace the src expression with "*/", I get all the files included, but the root folder is created as well.

Example output unzipped file:

bsd-client
     |_____ index.html
     |_____ js
            |_____ script.js

The output that I want to achieve is the following:

index.html
js
|_____ script.js

Can't this be done or is this a bug?

Compress empty folders

I'm trying a task with mode=zip, and it doesn't compress empty folders ... is there a way to compress empty folders ?
otherwise it would be nice to have an option to be able to compress empty folders

config question

Hey guys, quick question. The following config:

compress: {
  dist: {
    options: {
      archive: 'angular.zip'
    },
    src: ['build/**']
  }
}

produces angular.zip that when unzipped produces a folder that contains the correct files but is named build instead of angular. How do I make the unzipped dir name match the zip dir name?

In a previous version I was able to do this:

compress: {
  dist: { files: {'angular.zip': 'build/**'} }
}

Thanks!

cc @ctalkington

Non-deterministic corruption of resulting tarball on Mac OSX

Basically, the compress step produces a tarball that is 10 bytes in length about 20% of the time or something in that range, we've also potentially seen it produce a file that may be a somewhat longer, but still truncated number of bytes. 10 bytes seems to be the length for the typical error condition. We've only seen it on mac boxes so far, though we haven't really tested much on other boxes.

We witnessed this on several larger projects, so we broke it down to a very simple case (setup below), I test by running the following command repeatedly (previously we were hitting it using a more proper grunt work flow, this was just a simple command developed to test numerous times quickly):

rm -rf dist; grunt compress; ls -l dist; tar tzf dist/test.tar.gz

In the case that it fails the tar tzf command typically will output "tar: Error opening archive: (Empty error message)"

Project setup:


Root folder has the following contents:

/src/test.html (just an empty file for testing)
/Gruntfile.js
/package.json


Gruntfile.js contents:

/global module:false, node:true/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
meta: {
},
compress: {
test: {
options: {
archive: 'dist/test.tar.gz'
},
files: [
{expand: true, cwd: 'src', src: ['*']}
]
}
}
});

grunt.loadNpmTasks('grunt-contrib-compress');
};


package.json contents:

{
"name": "GruntCompress",
"version": "0.0.0",
"title": "",
"dependencies": {},
"devDependencies": {
"grunt": "~0.4",
"grunt-contrib-compress": "~0.4.0"
}
}

0.4.6 produces invalid gzip files

This plugin is producing invalid gzip files that are much larger than when I compress from the command line. I noticed that the gz files are larger than what I expected so I tried to gunzip them from the command line to see what was going on and I get the following error

gzip: index.html.gz: not in gzip format

here is a snapshot of the different sizes between the original, the grunt-contrib-compress and plain old gzip:

-rw-r--r--  1 jason  _www  5142 25 Mar 09:26 index.html
-rw-r--r--  1 jason  _www  2312 25 Mar 09:36 index.html.cmdline.gz
-rw-r--r--  1 jason  _www  4544 25 Mar 09:26 index.html.gz

I am using Mac OSX 10.8.2 and have recently installed grunt so I have the latest of everything.

Custom extention instead of ".gz"

Hey - Excellent work on the 0.5 version. Really appreciating it!

I would like to know if there's a possible way to define a custom extension like ".gz.js" instead of just ".gz".
I think it used to be possible somewhere in 0.4 (it just that in 0.4 gzip did not fully work for me)

If its not yet possible I would be able to fork and try implement it if you'd like.
My thoughts where to either add it to the options object:

options: {
    mode: 'gzip',
    ext: '.gz.js' // so file will be filename.gz.js instead of filename.gz
}

Or inside the files array,

files: [
   {src: ['path/*'], dest: 'internal_folder/', ext: '.gz.js'}
]

Exception "ReferenceError: emit is not defined" when no valid input files provided for zip

Specifying a configuration with options.mode: zip that contains no valid files results in an exception. The same error occurs if multiple invalid files are specified or if a path that does not expand to any existing files is specified.

Configuration:

compress: {
  zip: {
    options: {
      mode: 'zip'
    },
    files: {
      'build.zip': [
        'some/path/that/does/not/exist.txt'
      ]
    }
  }
}

Output:

Running "compress:zip" (compress) task

ReferenceError: emit is not defined
    at ZipStream.finalize (node_modules/grunt-contrib-compress/node_modules/zipstream/zipstream.js:89:5)
    at addFile (node_modules/grunt-contrib-compress/tasks/compress.js:179:15)
    at Object.module.exports.methods.zip (node_modules/grunt-contrib-compress/tasks/compress.js:191:7)
    at module.exports.getSize (node_modules/grunt-contrib-compress/tasks/compress.js:85:20)
    at async.forEachSeries.iterate (node_modules/grunt/node_modules/async/lib/async.js:108:13)
    at Object.async.forEachSeries (node_modules/grunt/node_modules/async/lib/async.js:124:9)
    at Object.module.exports.getSize (node_modules/grunt-contrib-compress/tasks/compress.js:72:11)
    at Object.task.registerMultiTask.thisTask (node_modules/grunt/lib/grunt/task.js:109:15)
    at Object.task.registerTask.thisTask.fn (node_modules/grunt/lib/grunt/task.js:58:16)
    at Task.<anonymous> (node_modules/grunt/lib/util/task.js:341:36)

However, if at least one valid file is specified, the task completes without error.

I would expect a fatal error if no files are not found, and a warning if one of the supplied paths does not expand to any existing files. Without a warning or error, a build zip that is missing critical files could go out unnoticed.

What is the expected behavior for file not found?

Getting this error: Fatal error: EISDIR, read

tried running compress task using default config from docs, also tried slightly altering to match what I have working for imagemin

using grunt 0.4.1 and grunt-contrib-compress 0.5.0

    // gzip assets 1-to-1 for production
    ,compress: {
      main: {
        options: {
          mode: 'gzip'
        }
        ,files: [ {
          expand: true 
          ,cwd: 'production/' 
          ,src: '**/*' 
          ,dest: 'production/'
        } ]
      }
    }

Final file missing from archive

My GruntFile.js is configured to use compression in the following way (mix of directories and files):

compress: {
main: {
options: {
mode: 'tar',
archive: 'dist/com_academicpages.tar'
},
files: [
{src: ['admin/'], dest: 'com_academicpages'},
{src: ['site/
'], dest: 'com_academicpages'},
{src: ['index.html'], dest:'com_academicpages'},
{src: ['install.xml'], dest:'com_academicpages'},
{src: ['package.json'], dest:'com_academicpages'}
]
}
}

Directories parse correctly and show up in working tar. The final file in the array is being dropped, however (I added my package.json to test this).

This worked correctly with Grunt 0.4.0 and compress @ ~0.4.1.

Tarring and untarring without the current directory.

Currently when you tar, it takes the parent directory aswell.

I tried using flatten and it removed the "src" folder.

But it still has the parent containing folder.

How can I tar it so there's no parent containing folder.

This seems to be a problem everywhere:

http://stackoverflow.com/questions/3466046/untar-contents-to-same-directory?rq=1
http://stackoverflow.com/questions/845593/how-do-i-untar-a-subdirectory-into-the-current-directory
http://stackoverflow.com/questions/2650935/how-can-i-untar-a-sub-directory?rq=1

Is there a way to include/compress an emtpy directory?

I specified an empty directory (i.e. logs) to be zipped but it doesn't seem to work.
Is this a known limitation or am I doing something wrong?

compress: {
  deploy: {
    options: {
      archive: 'deploy.zip'
      mode: 'zip'
    },
    files: [
      {src: [logs\**]}
    ]
  }
}

Thanks

Please support setting the compression level for gzip

I just noticed the fix for gzip which supports compressing files individually (GH-26). Would it be possible to also support compression levels for gzip? I've written a custom task to gzip files at level 9 and it seems to work well but I'd much rather use the contrib compression task instead.

Thanks!

Update for compatibility with grunt 0.4.0rc5

I need someone to help update this plugin to work with grunt 0.4.0rc5.

I had to revert the whole file src-dest mappings implicit iteration abstraction per gruntjs/grunt#606, and once again, multi tasks have to iterate over this.files manually. In addition, there's a new this.filesSrc array that contains a reduced, uniqued set of all matched src files in case the task is read-only and only cares about source files.

See:

Notes:

  • A user may specify a new option nonull in addition to src to tell grunt to keep patterns or filepaths that don't actually match files. Because of this, the task shouldn't explode if a nonexistent src filepath is encountered. I handle this in the grunt-contrib-concat by warning if not grunt.file.exists but not failing the task.

Guidelines for updating / publishing this plugin:

  • Change this project's version number to one ending in "rc5" so that it's clearer that it works with grunt 0.4.0rc5. If the existing version number doesn't end in an "a" or "rc" increment the patch version. Eg, jshint went from 0.1.0 -> 0.1.1rc5
  • Ensure grunt 0.4.0rc5-compatible plugins are specified in package.json devDependencies like this (grunt-contrib-internal can be "*")
  • Update the CHANGELOG like this
  • Regenerate the README.md file via grunt.
  • Delete node_modules, run npm cache clean and re-run npm install to test.
  • Publish to npm using --tag=master (not latest)

Empty zip folder created

My Grunt Task

compress: {
    main: {
      options: {
        archive: "./release/archive.zip"
      },
      files: [
        {
          src: ["**"], cwd: ''./bin/debug/"
        }
      ]
    }
  }

My folder Structure is like this

-bin
-- debug
---- a
---- b
------ x
------ y
---- c
--release

I want to zip everything that is inside the debug folder and put it inside the release folder and the zip to not have the bin/debug structure. Unfortunately the zip file created is empty with this task. Please help.

.files not added to archive

Maybe I am missing some part of the config, but it does not seem to archive my .htaccess file... Any idea ?

When src filenames use the same name but different extension, gzip dest is wrong

Hi

Given two files, one.js and one.min.js, with the code

        compress: {
            main: {
                options: {
                    mode: 'gzip'
                },
                files: [
                    {expand: true,
                        src: ['one.js', 'one.min.js'], dest: '../../assets/javascript', ext: '.js'}
                ]
            }
        },

Then it will create only one gzip file, not two. It's confused by the "min" name.

Running "compress:main" (compress) task
Created ../../assets/javascript/one.js.gz (20 bytes)
Created ../../assets/javascript/one.js.gz (20 bytes)

Task "compress" not found.

Task in the Gruntfile:

    compress: {
      main: {
        options: {
          archive: 'frontend-pack.zip'
        },
        files: [
          {src: ['**'], dest: 'clickdummy/'}
        ]
      }
    }

The registration:

grunt.registerTask('pack', ['compress']);

The error:

Loading "Gruntfile.js" tasks...OK
+ default, pack, qa

Running tasks: pack

Running "pack" task
Warning: Task "compress" not found. Use --force to continue.

grunt-contrib-compress 0.5.2
The folder has numerous nested subfolders.

Compress breaks list of tasks

Hi,

When I have "compress:main" task in the middle of the task's list, it breaks all the task after it. Maybe there is a better way to call tasks after "compress:main". Please help.

Best,
Krzysztof

Compress symlinks?

Is there a way to compress the symlink as-is instead of copying the content of where it's originally pointing to?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.