Skip to content

Commit

Permalink
Cleanup of unused dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dvonlehman committed Nov 16, 2015
1 parent b50ed96 commit 1fb661e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 54 deletions.
26 changes: 2 additions & 24 deletions lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ var _ = require('lodash');
var awsConfig = require('aws-config');
var urljoin = require('url-join');
var mime = require('mime');
var csvToJson = require('csvtojson');
var debug = require('debug')('4front:plugins:s3-proxy');
var debug = require('debug')('s3-proxy');

require('simple-errors');

Expand Down Expand Up @@ -71,9 +70,7 @@ module.exports = function(options) {
var headerValue = s3Headers[header];

if (header === 'content-type') {
if (options.csvToJson === true) {
headerValue = 'application/json; charset=utf-8';
} else if (headerValue === 'application/octet-stream') {
if (headerValue === 'application/octet-stream') {
// If the content-type from S3 is the default "application/octet-stream",
// try and get a more accurate type based on the extension.
headerValue = mime.lookup(req.path);
Expand Down Expand Up @@ -111,25 +108,6 @@ module.exports = function(options) {
return next(err);
});

if (options.csvToJson === true) {
var converter = new csvToJson.Converter({constructResult: false});

var recordsWritten = false;
converter.on('record_parsed', function() {
if (recordsWritten) {
res.write(',');
} else {
res.write('[');
recordsWritten = true;
}
});
converter.on('end_parsed', function() {
res.write(']');
});

readStream = readStream.pipe(converter);
}

readStream.pipe(res);
}

Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "s3-proxy",
"version": "1.0.1",
"version": "1.0.2",
"description": "Streaming http proxy Express middleware for fetching bjects from S3",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -30,10 +30,7 @@
"async": "^1.4.0",
"aws-config": "^1.0.3",
"aws-sdk": "^2.1.47",
"body-parser": "^1.14.1",
"csvtojson": "^0.4.3",
"debug": "^2.2.0",
"https-proxy-agent": "^1.0.0",
"lodash": "^3.10.1",
"mime": "^1.3.4",
"simple-errors": "^1.0.1",
Expand Down
27 changes: 1 addition & 26 deletions test/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var assert = require('assert');
var urljoin = require('url-join');
var express = require('express');
var supertest = require('supertest');
var debug = require('debug')('4front:plugins:s3-proxy:test');
var debug = require('debug')('s3-proxy:test');

require('simple-errors');
require('dash-assert');
Expand Down Expand Up @@ -228,31 +228,6 @@ describe('S3Storage', function() {
});
});

it('transforms csv to json output', function(done) {
var csvFile = 'first,last,age\n' +
'Frank,Smith,40\n' +
'Sally,Thomas,27\n' +
'Bruno,Schmidt,47';

this.pluginOptions.csvToJson = true;

var key = 'people.csv';
this.s3.get('/' + BUCKET_NAME + '/' + key, function(req, res, next) {
res.set('Content-Type', 'text/csv');
res.end(csvFile);
});

supertest(self.app)
.get(urljoin('/s3-proxy', key))
.expect(200)
.expect('content-type', 'application/json; charset=utf-8')
.expect(function(res) {
assert.equal(3, res.body.length);
assert.deepEqual(res.body[0], {first: 'Frank', last: 'Smith', age: 40});
})
.end(done);
});

describe('lists keys', function() {
beforeEach(function() {
self = this;
Expand Down

0 comments on commit 1fb661e

Please sign in to comment.