diff --git a/lib/reader.js b/lib/reader.js index 17e9d3b5..9704281b 100644 --- a/lib/reader.js +++ b/lib/reader.js @@ -236,7 +236,7 @@ class ParquetEnvelopeReader { } static async openS3(client, params) { - let fileStat = await client.headObject(params).promise(); + let fileStat = async () => client.headObject(params).promise().then(d => d.ContentLength); let readFn = async (offset, length) => { let Range = `bytes=${offset}-${offset+length-1}`; @@ -246,7 +246,7 @@ class ParquetEnvelopeReader { let closeFn = () => ({}); - return new ParquetEnvelopeReader(readFn, closeFn, fileStat.ContentLength); + return new ParquetEnvelopeReader(readFn, closeFn, fileStat); } static async openUrl(request, params) { @@ -259,7 +259,7 @@ class ParquetEnvelopeReader { let defaultHeaders = params.headers || {}; - let filesize = await new Promise( (resolve, reject) => { + let filesize = async () => new Promise( (resolve, reject) => { let req = request(params); req.on('response', res => { req.abort(); @@ -350,6 +350,9 @@ class ParquetEnvelopeReader { } async readFooter() { + if (typeof this.fileSize === 'function') { + this.fileSize = await this.fileSize(); + } let trailerLen = PARQUET_MAGIC.length + 4; let trailerBuf = await this.read(this.fileSize - trailerLen, trailerLen);