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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user