Skip to content

Commit

Permalink
Allow this.fileSize to be an async function as well
Browse files Browse the repository at this point in the history
Instantiating a new client blocks on retrieving filesize.  But there are cases when we really don't need the filesize, for example when we have the metadata cached already.
  • Loading branch information
ZJONSSON committed Feb 18, 2018
1 parent cc67213 commit e3c70df
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand All @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit e3c70df

Please sign in to comment.