From 3ee8d2313cace7be8decd5b1b595eb51000b09ba Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Mon, 14 Nov 2022 16:39:20 -0500 Subject: [PATCH] editorial: make Blob.slice a separate algorithm (#183) Split out Blob.slice into its own algorithm that other implementations may use and call this algorithm from Blob.slice. --- index.bs | 124 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 75 insertions(+), 49 deletions(-) diff --git a/index.bs b/index.bs index 8aed964..2300f71 100644 --- a/index.bs +++ b/index.bs @@ -193,6 +193,76 @@ The term Unix Epoch is used in this specification to r (or 1970-01-01T00:00:00Z ISO 8601); this is the same time that is conceptually "0" in ECMA-262 [[ECMA-262]]. +
+The slice blob algorithm given a {{Blob}} blob, +an optional parameter start, an optional parameter end, +and an optional parameter contentType is used to refer to the following +steps and returns a new {{Blob}} containing the bytes ranging from the start parameter +up to but not including the end parameter. It must act as follows: + +1. Let originalSize be blob's {{Blob/size}}. + +1. The optional start parameter is a value for the start point of a slice blob + call, and must be treated as a byte-order position, with the zeroth position representing the + first byte. User agents must normalize start according to the following: + +
    +
  1. If the optional start parameter is not used as a parameter when making this call, + let relativeStart be 0. + +
  2. If start is negative, let relativeStart be + max((originalSize + start), 0). + +
  3. Otherwise, let relativeStart be + min(start, originalSize). +
+ +1. The optional end parameter is a value for the end point of a slice blob call. + User agents must normalize end according to the following: + +
    +
  1. If the optional end parameter is not used as a parameter when making this call, + let relativeEnd be originalSize. + +
  2. If end is negative, let relativeEnd be + max((originalSize + end), 0). + +
  3. Else, let relativeEnd be + min(end, originalSize). +
+ +1. The optional contentType parameter is used to set the ASCII-encoded string in lower + case representing the media type of the {{Blob}}. User agents must normalize + contentType according to the following: + +
    +
  1. If the contentType parameter is not provided, let relativeContentType + be set to the empty string. + +
  2. Otherwise, let relativeContentType be set to contentType and run the + substeps below: + 1. If relativeContentType contains any characters outside the range of U+0020 to + U+007E, then set relativeContentType to the empty string and return from these + substeps. + 2. Convert every character in relativeContentType to [=ASCII lowercase=]. +
+ +1. Let span be max((relativeEnd - relativeStart), 0). + +1. Return a new {{Blob}} object S with the following characteristics: + +
    +
  1. S refers to span consecutive bytes from blob's + associated byte sequence, beginning with the byte at byte-order position + relativeStart. + +
  2. S.{{Blob/size}} = span. + +
  3. S.{{Blob/type}} = relativeContentType. +
+ +
+