Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow files in directories to be downloaded onto local machine #2199

Merged
merged 15 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import * as resumableUpload from './resumable-upload';
import {Writable, Readable, pipeline, Transform, PassThrough} from 'stream';
import * as zlib from 'zlib';
import * as http from 'http';
import * as path from 'path';

import {
ExceptionMessages,
Expand Down Expand Up @@ -2098,6 +2099,8 @@ class File extends ServiceObject<File> {
const fileStream = this.createReadStream(options);
let receivedData = false;
if (destination) {
fs.mkdirSync(path.dirname(destination), {recursive: true});
hochoy marked this conversation as resolved.
Show resolved Hide resolved
hochoy marked this conversation as resolved.
Show resolved Hide resolved

fileStream
.on('error', callback)
.once('data', data => {
Expand Down
3 changes: 3 additions & 0 deletions src/transfer-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ export class TransferManager {
prefix: filesOrFolder,
});
files = directoryFiles[0];
// filter out directories
files = files.filter(file => !file.name.endsWith('/'));
} else {
files = filesOrFolder.map(curFile => {
if (typeof curFile === 'string') {
Expand All @@ -258,6 +260,7 @@ export class TransferManager {
{},
options.passthroughOptions
);

if (options.prefix) {
passThroughOptionsCopy.destination = path.join(
options.prefix || '',
Expand Down