return through2map.obj(function vinylStream(object) { var base = options.base || object.Bucket, file = new File({ base: base, cwd: options.cwd, contents: object.Body, stat: { mtime: new Date(object.LastModified), size: parseInt(object.ContentLength, 10) }, path: base + '/' + object.Key }); // Set the length on things like streams which are used // by some frameworks. if (!file.isNull() && !file.contents.length) { file.contents.length = file.stat.size; } // Assign AWS metadata to vinyl files if (options.meta) { // Support for Content-Type if (object.ContentType) { file.contentType = object.ContentType; } } return file; });
it('should throw an error if a Stream is input', () => { resetAll(); const pluginStream = plugin(OPTS), passedFile = new File({ contents: new (require('stream')).Readable({objectMode: true}) .wrap(require('event-stream').readArray(['stream', 'with', 'those', 'contents'])) }); expect(passedFile.isNull()).to.be.false; expect(passedFile.isStream()).to.be.true; expect(passedFile.isBuffer()).to.be.false; expect(() => { pluginStream.write(passedFile); }).to.throw('Streaming not supported'); expect(htmlclean.notCalled).to.be.true; });
it('should skip process if a null is input', done => { resetAll(); const pluginStream = plugin(OPTS), passedFile = new File(); expect(passedFile.isNull()).to.be.true; expect(passedFile.isStream()).to.be.false; expect(passedFile.isBuffer()).to.be.false; pluginStream.write(passedFile); pluginStream.once('data', file => { expect(file.isNull()).to.be.true; expect(file.isStream()).to.be.false; expect(file.isBuffer()).to.be.false; expect(htmlclean.notCalled).to.be.true; done(); }); });