-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate Changes
- Loading branch information
Showing
7 changed files
with
54 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { streamToString } from '../../src/s3' | ||
import stream from 'stream' | ||
|
||
describe('streamToString', () => { | ||
it('should convert a stream to a string', async () => { | ||
const readable = new stream.Readable() | ||
|
||
readable._read = () => {} | ||
readable.push('Hello, ') | ||
readable.push('world!') | ||
readable.push(null) | ||
|
||
const result = await streamToString(readable) | ||
expect(result).toEqual('Hello, world!') | ||
}) | ||
|
||
it('should convert a JSON stream to a string', async () => { | ||
const json = { name: 'John Doe', age: 30 } | ||
const jsonString = JSON.stringify(json) | ||
const readable = new stream.Readable() | ||
|
||
readable._read = () => {} | ||
readable.push(jsonString) | ||
|
||
const result = await streamToString(readable) | ||
expect(result).toEqual(jsonString) | ||
}) | ||
|
||
|
||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { Readable } from 'stream'; | ||
|
||
export const streamToString = async (stream: Readable | ReadableStream | Blob) => new Promise((resolve, reject) => { | ||
const chunks = [] | ||
stream.on('data', chunk => chunks.push(chunk)) | ||
export const streamToString = async (stream: Readable) => new Promise((resolve, reject) => { | ||
const chunks: any[] = [] | ||
|
||
stream.on('data', (chunk: any) => chunks.push(chunk)) | ||
stream.on('error', reject) | ||
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8'))) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './s3Service' | ||
|
||
export * from './formatters' |