Skip to content

Commit dd5ae7f

Browse files
AVaksmanBenjamin E. Coe
authored andcommitted
feat: adds support for asyncIterators (via readable-stream@3 dependency)
1 parent 5f69a3d commit dd5ae7f

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"onetime": "^5.1.0",
6969
"p-limit": "^2.2.0",
7070
"pumpify": "^2.0.0",
71+
"readable-stream": "^3.4.0",
7172
"snakeize": "^0.1.0",
7273
"stream-events": "^1.0.1",
7374
"through2": "^3.0.0",

src/file.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,9 @@ class File extends ServiceObject<File> {
11901190

11911191
// tslint:disable-next-line:no-any
11921192
let validateStream: any; // Created later, if necessary.
1193+
1194+
// TODO: remove `through2` dependency in favor of native PassThrough
1195+
// once Node 8 support is discontinued
11931196
const throughStream = streamEvents(through()) as Duplex;
11941197

11951198
let crc32c = true;

system-test/storage.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,19 @@ describe('storage', () => {
20612061
});
20622062
});
20632063

2064+
it('should support readable[Symbol.asyncIterator]()', async () => {
2065+
const fileContents = fs.readFileSync(FILES.big.path);
2066+
2067+
const [file] = await bucket.upload(FILES.big.path);
2068+
const stream = file.createReadStream();
2069+
const chunks: Buffer[] = [];
2070+
for await (const chunk of stream) {
2071+
chunks.push(chunk);
2072+
}
2073+
const remoteContents = Buffer.concat(chunks).toString();
2074+
assert.strictEqual(String(fileContents), String(remoteContents));
2075+
});
2076+
20642077
it('should download a file to memory', done => {
20652078
const fileContents = fs.readFileSync(FILES.big.path);
20662079
bucket.upload(FILES.big.path, (err: Error | null, file?: File | null) => {

0 commit comments

Comments
 (0)