MCPcopy Index your code
hub / github.com/nodejs/node / slice

Method slice

lib/internal/blob.js:244–282  ·  view source on GitHub ↗

* @param {number} [start] * @param {number} [end] * @param {string} [contentType] * @returns {Blob}

(start = 0, end = this[kLength], contentType = '')

Source from the content-addressed store, hash-verified

242 * @returns {Blob}
243 */
244 slice(start = 0, end = this[kLength], contentType = '') {
245 if (!isBlob(this))
246 throw new ERR_INVALID_THIS('Blob');
247
248 start = converters['long long'](
249 start,
250 { __proto__: null, context: 'start' },
251 );
252 end = converters['long long'](
253 end,
254 { __proto__: null, context: 'end' },
255 );
256
257 if (start < 0) {
258 start = MathMax(this[kLength] + start, 0);
259 } else {
260 start = MathMin(start, this[kLength]);
261 }
262
263 if (end < 0) {
264 end = MathMax(this[kLength] + end, 0);
265 } else {
266 end = MathMin(end, this[kLength]);
267 }
268
269 contentType = `${contentType}`;
270 if (RegExpPrototypeExec(disallowedTypeCharacters, contentType) !== null) {
271 contentType = '';
272 } else {
273 contentType = StringPrototypeToLowerCase(contentType);
274 }
275
276 const span = MathMax(end - start, 0);
277
278 return createBlob(
279 this[kHandle].slice(start, start + span),
280 span,
281 contentType);
282 }
283
284 /**
285 * @returns {Promise<ArrayBuffer>}

Callers 1

mainFunction · 0.95

Calls 3

isBlobFunction · 0.85
createBlobFunction · 0.85
sliceMethod · 0.65

Tested by

no test coverage detected