Skip to content

Commit

Permalink
fix: duplex stream does not implement methods like _read (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Aug 6, 2019
1 parent 69364cc commit 22ee26c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {Agent} from 'https';
import fetch, * as f from 'node-fetch';
import {PassThrough, Readable, Duplex} from 'stream';
import {PassThrough, Readable} from 'stream';
import * as uuid from 'uuid';

export interface CoreOptions {
Expand Down Expand Up @@ -55,7 +55,7 @@ export interface OptionsWithUrl extends CoreOptions {

export type Options = OptionsWithUri | OptionsWithUrl;

export interface Request extends Duplex {
export interface Request extends PassThrough {
agent: Agent | false;
headers: Headers;
href?: string;
Expand Down Expand Up @@ -264,7 +264,7 @@ function teenyRequest(

if (callback === undefined) {
// Stream mode
const requestStream = new Duplex();
const requestStream = new PassThrough();
options.compress = false;
fetch(uri, options).then(
res => {
Expand Down
16 changes: 16 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {Readable} from 'stream';
import * as sinon from 'sinon';
import {teenyRequest} from '../src';

import {PassThrough} from 'stream';

// tslint:disable-next-line variable-name
const HttpsProxyAgent = require('https-proxy-agent');

Expand Down Expand Up @@ -156,4 +158,18 @@ describe('teeny', () => {
});
}
});

// see: https:/googleapis/nodejs-storage/issues/798
it('should not throw exception when piped through pumpify', () => {
const scope = mockJson();
teenyRequest({uri}).pipe(new PassThrough());
});

it('should emit response event when called without callback', done => {
const scope = mockJson();
teenyRequest({uri}).on('response', res => {
assert.ok(res);
return done();
});
});
});

0 comments on commit 22ee26c

Please sign in to comment.