使用gulp-vinyl-zip创建zip文件时出现TypeError

时间:2015-05-29 04:22:08

标签: node.js zip gulp

我正在尝试使用Gulp创建包含符号链接的Mac应用程序的zip文件。我正在使用gulp-vinyl-zip来绕过lack of symlink support in the output of dest

var gulp = require('gulp');
var zip = require('gulp-vinyl-zip');

gulp.task('default', function () {
    return gulp.src('tmp/Application.app/**/*')
        .pipe(zip.dest('releases/Application.zip'));
});

但是我收到以下错误:

buffer.js:84
    throw new TypeError('must start with number, buffer, array or    string');
          ^
TypeError: must start with number, buffer, array or string
    at fromObject (buffer.js:84:11)
    at new Buffer (buffer.js:52:3)
    at DestroyableTransform.through.obj.stream.push.File.path [as _transform] (/opt/ygor/client/node_modules/gulp-vinyl-zip/lib/zip/index.js:24:21)
    at DestroyableTransform.Transform._read (/opt/ygor/client/node_modules/gulp-vinyl-zip/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (/opt/ygor/client/node_modules/gulp-vinyl-zip/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
    at doWrite (/opt/ygor/client/node_modules/gulp-vinyl-zip/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:237:10)
    at writeOrBuffer (/opt/ygor/client/node_modules/gulp-vinyl-zip/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:227:5)
    at DestroyableTransform.Writable.write (/opt/ygor/client/node_modules/gulp-vinyl-zip/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:194:11)
    at DestroyableTransform._transform (/opt/ygor/client/node_modules/gulp-vinyl-zip/lib/dest/index.js:13:9)
    at DestroyableTransform.Transform._read (/opt/ygor/client/node_modules/gulp-vinyl-zip/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)

正在寻找解决方案,我认为可能需要缓冲而不是流式乙烯基文件对象,所以我尝试将乙烯基缓冲区添加到管道中:

var gulp = require('gulp');
var zip = require('gulp-vinyl-zip');
var buffer = require('vinyl-buffer');

gulp.task('default', function () {
    return gulp.src('tmp/Application.app/**/*')
        .pipe(buffer())
        .pipe(zip.dest('releases/Application.zip'));
});

但我仍然收到相同的错误消息。作为Gulp的新手,我想我错过了一些基本的东西。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您可能想使用os内置zip命令:

gulp.task('default', function(cb) {
    require('child_process').exec('zip --symlinks -r ../releases/Application.zip Application.app', {
        cwd: 'tmp'
    }, function(err, stdout, stderr) {
        err ? console.err(stderr) : console.log(stdout);
        cb(err);
    });
});