Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing isNull check for mapping vinyl metadata. #11

Merged
merged 1 commit into from
Apr 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
});
});