Skip to content

Commit

Permalink
fix: set chunk size value
Browse files Browse the repository at this point in the history
  • Loading branch information
kukhariev committed Apr 22, 2019
1 parent a007213 commit caf4ac4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/uploadx/src/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BackoffRetry } from './backoff_retry';
import { UploaderOptions, UploadItem, UploadState, UploadStatus } from './interfaces';
import { unfunc } from './utils';
const noop = () => {};
const DEFAULT_CHUNK_SIZE = 1_048_576;
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD';

/**
Expand Down Expand Up @@ -80,7 +81,7 @@ export abstract class Uploader {
/**
* Chunk size in bytes
*/
chunkSize: number;
chunkSize: number = DEFAULT_CHUNK_SIZE;
/**
* Auth Bearer token/tokenGetter
*/
Expand Down Expand Up @@ -114,6 +115,7 @@ export abstract class Uploader {
this.size = file.size;
this.mimeType = file.type || 'application/octet-stream';
this.stateChange = options.stateChange || noop;
this.chunkSize = options.chunkSize || this.chunkSize;
this.configure(options);
}

Expand Down
5 changes: 5 additions & 0 deletions src/uploadx/src/uploaderx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ describe('Uploader', () => {
const uploader: Uploader = new UploaderX(file, {} as UploadxOptions);
expect(uploader.chunkSize).toEqual(1_048_576);
});
it('should set chunkSize', async function() {
const file = getFile();
const uploader: Uploader = new UploaderX(file, { chunkSize: 4_194_304 } as UploadxOptions);
expect(uploader.chunkSize).toEqual(4_194_304);
});
it('should upload', async function() {
const file = getFile();
const uploader: Uploader = new UploaderX(file, {} as UploadxOptions);
Expand Down
2 changes: 0 additions & 2 deletions src/uploadx/src/uploaderx.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { UploadxOptions } from './interfaces';
import { Uploader } from './uploader';
import { resolveUrl } from './utils';
const DEFAULT_CHUNK_SIZE = 1_048_576;
/**
* Implements XHR/CORS Resumable Upload
* @see
* https://developers.google.com/drive/v3/web/resumable-upload
*/
export class UploaderX extends Uploader {
chunkSize = DEFAULT_CHUNK_SIZE;
constructor(readonly file: File, options: UploadxOptions) {
super(file, options);
this.responseType = 'json' as XMLHttpRequestResponseType;
Expand Down

0 comments on commit caf4ac4

Please sign in to comment.