Skip to content

Commit

Permalink
Merge pull request #11 from izaakschroeder/fix-null-case
Browse files Browse the repository at this point in the history
Add missing `isNull` check for mapping vinyl metadata.
  • Loading branch information
izaakschroeder committed Apr 15, 2015
2 parents d609d85 + 3f0ca27 commit 47ed2c2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Features:

```javascript
var gulp = require('gulp'),
AWS = require('aws-sdk'),
s3 = require('vinyl-s3');

// Upload files to S3
Expand All @@ -37,13 +36,14 @@ gulp.task('download', function() {
});

// Just print a list of files
var through2 = require('through2');
gulp.task('meta', function() {
return s3.src('s3://my-bucket/foo/**/*.jpg', { read: false })
.pipe(through2.obj(function(file, _, callback) {
console.log('found:',file.path);
console.log(file.path);
callback();
}));
})
});
```

When working with large files you may find it useful to use streaming mode instead of buffering mode. You can enable this in the `src()` family of functions by setting `{ buffer: false }`. The default mode is to use buffering as is the same with `fs.src`.
Expand Down
18 changes: 18 additions & 0 deletions example/meta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node

'use strict';

var argv = require('yargs').argv;

var through2 = require('through2'),
s3 = require('vinyl-s3');

// env AWS_PROFILE="home" ./example/meta.js "s3://my-bucket/foo/**/*.jpg"
s3.src(argv._, { read: false })
.pipe(through2.obj(function onFile(file, enc, callback) {
console.log(file.path);
callback();
}))
.on('finish', function onFinish() {
console.log('Done.');
});
2 changes: 1 addition & 1 deletion lib/vinyl-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = function createVinylStream(options) {

// Set the length on things like streams which are used
// by some frameworks.
if (!file.contents.length) {
if (!file.isNull() && !file.contents.length) {
file.contents.length = file.stat.size;
}

Expand Down
6 changes: 6 additions & 0 deletions test/spec/vinyl-stream.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ describe('#createVinylStream', function() {
stream.write({ ContentType: 'foo/bar', Key: 'key', Body: body, ContentLength: '20' });
expect(stream.read().contents).to.have.property('length', 20);
});

it('should work with null vinyl objects', function() {
var stream = createVinylStream({ meta: true });
stream.write({ ContentType: 'foo/bar', Key: 'key' });
expect(stream.read()).to.not.be.null;
});
});

0 comments on commit 47ed2c2

Please sign in to comment.