1 | /**
|
2 | * -------------------------------------------------------------------------------------------
|
3 | * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
4 | * See License in the project root for license information.
|
5 | * -------------------------------------------------------------------------------------------
|
6 | */
|
7 |
|
8 | /**
|
9 | * @module OneDriveLargeFileUploadTaskUtil
|
10 | */
|
11 |
|
12 | /**
|
13 | * @constant
|
14 | * Default value for the rangeSize
|
15 | * Recommended size is between 5 - 10 MB {@link https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_createuploadsession#best-practices}
|
16 | */
|
17 | const DEFAULT_FILE_SIZE: number = 5 * 1024 * 1024;
|
18 |
|
19 | /**
|
20 | * @constant
|
21 | * Rounds off the given value to a multiple of 320 KB
|
22 | * @param {number} value - The value
|
23 | * @returns The rounded off value
|
24 | */
|
25 | const roundTo320KB = (value: number): number => {
|
26 | if (value > 320 * 1024) {
|
27 | value = Math.floor(value / (320 * 1024)) * 320 * 1024;
|
28 | }
|
29 | return value;
|
30 | };
|
31 |
|
32 | /**
|
33 | * @constant
|
34 | * Get the valid rangeSize for a file slicing (validity is based on the constrains mentioned in here
|
35 | * {@link https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_createuploadsession#upload-bytes-to-the-upload-session})
|
36 | *
|
37 | * @param {number} [rangeSize = DEFAULT_FILE_SIZE] - The rangeSize value.
|
38 | * @returns The valid rangeSize
|
39 | */
|
40 | export const getValidRangeSize = (rangeSize: number = DEFAULT_FILE_SIZE): number => {
|
41 | const sixtyMB = 60 * 1024 * 1024;
|
42 | if (rangeSize > sixtyMB) {
|
43 | rangeSize = sixtyMB;
|
44 | }
|
45 | return roundTo320KB(rangeSize);
|
46 | };
|