forked from microsoftgraph/msgraph-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOneDriveLargeFileUploadTaskUtil.ts
More file actions
35 lines (32 loc) · 1.19 KB
/
Copy pathOneDriveLargeFileUploadTaskUtil.ts
File metadata and controls
35 lines (32 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* @module OneDriveLargeFileUploadTaskUtil
*/
/**
* Default value for the rangeSize
* 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}
*/
const DEFAULT_FILE_SIZE: number = 5 * 1024 * 1024;
/**
* Rounds off the given value to a multiple of 320 KB
* @param {number} value - The value
* @return The rounded off value
*/
const roundTo320KB = (value: number): number => {
if (value > (320 * 1024)) {
value = Math.floor(value / (320 * 1024)) * 320 * 1024;
}
return value;
}
/**
* Get the valid rangeSize for a file slicing (validity is based on the constrains mentioned in here {@link https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_createuploadsession#upload-bytes-to-the-upload-session})
*
* @param {number} [rangeSize = DEFAULT_FILE_SIZE] - The rangeSize value.
* @return The valid rangeSize
*/
export const getValidRangeSize = (rangeSize: number = DEFAULT_FILE_SIZE): number => {
const sixtyMB = 60 * 1024 * 1024;
if (rangeSize > sixtyMB) {
rangeSize = sixtyMB;
}
return roundTo320KB(rangeSize);
}