Raw slice with from (like subarray) (#2879)

* Raw slice with from (like subarray)

* Dep bumps

* 2.8.2

* re-use toU8a()

* Uint8Array.from

* slice on derived comment
This commit is contained in:
Jaco Greeff
2020-11-28 12:00:29 +01:00
committed by GitHub
parent a1a73cbf01
commit d65eb7a27f
12 changed files with 95 additions and 84 deletions
+12 -1
View File
@@ -95,12 +95,23 @@ export class Raw extends Uint8Array implements IU8a {
return this.eq(decodeU8a(other));
}
/**
* @description Create a new slice from the actual buffer. (compat)
* @param start The position to start at
* @param end The position to end at
*/
public slice (start?: number, end?: number): Uint8Array {
// Like subarray below, we have to follow this approach since we are extending the TypeArray.
// This happens especially when it comes to further extensions, the length may be an override
return Uint8Array.from(this).slice(start, end);
}
/**
* @description Create a new subarray from the actual buffer. (compat)
* @param begin The position to start at
* @param end The position to end at
*/
public subarray (begin: number, end?: number): Uint8Array {
public subarray (begin?: number, end?: number): Uint8Array {
return Uint8Array.from(this).subarray(begin, end);
}