source: frontend/node_modules/workbox-range-requests/utils/calculateEffectiveBoundaries.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*
2 Copyright 2018 Google LLC
3
4 Use of this source code is governed by an MIT-style
5 license that can be found in the LICENSE file or at
6 https://opensource.org/licenses/MIT.
7*/
8import { WorkboxError } from 'workbox-core/_private/WorkboxError.js';
9import { assert } from 'workbox-core/_private/assert.js';
10import '../_version.js';
11/**
12 * @param {Blob} blob A source blob.
13 * @param {number} [start] The offset to use as the start of the
14 * slice.
15 * @param {number} [end] The offset to use as the end of the slice.
16 * @return {Object} An object with `start` and `end` properties, reflecting
17 * the effective boundaries to use given the size of the blob.
18 *
19 * @private
20 */
21function calculateEffectiveBoundaries(blob, start, end) {
22 if (process.env.NODE_ENV !== 'production') {
23 assert.isInstance(blob, Blob, {
24 moduleName: 'workbox-range-requests',
25 funcName: 'calculateEffectiveBoundaries',
26 paramName: 'blob',
27 });
28 }
29 const blobSize = blob.size;
30 if ((end && end > blobSize) || (start && start < 0)) {
31 throw new WorkboxError('range-not-satisfiable', {
32 size: blobSize,
33 end,
34 start,
35 });
36 }
37 let effectiveStart;
38 let effectiveEnd;
39 if (start !== undefined && end !== undefined) {
40 effectiveStart = start;
41 // Range values are inclusive, so add 1 to the value.
42 effectiveEnd = end + 1;
43 }
44 else if (start !== undefined && end === undefined) {
45 effectiveStart = start;
46 effectiveEnd = blobSize;
47 }
48 else if (end !== undefined && start === undefined) {
49 effectiveStart = blobSize - end;
50 effectiveEnd = blobSize;
51 }
52 return {
53 start: effectiveStart,
54 end: effectiveEnd,
55 };
56}
57export { calculateEffectiveBoundaries };
Note: See TracBrowser for help on using the repository browser.