What makes RunKit call a `Buffer` an `Uint8Array`?


#1

All the methods below return a Buffer that created with Buffer.from(<ArrayBuffer>). But RunKit displays Uint8Array instead of Buffer for some of the return values. I know that Buffer extends (inherits from) Uint8Array and I hate this inconsistency. I want to know the reason why RunKit is working in such a manner and want it to be fixed.

const SHA2 = require("sha2");

const input = "RunKit";

console.log(SHA2.sha224(input)); // Uint8Array <995121D5308608FDD9010C144572…>
console.log(SHA2.sha256(input)); // Uint8Array <34D87C104EAFA4F2AB9C1DE183FA…>
console.log(SHA2.sha384(input)); // Uint8Array <34E4BD4057F0FCA6E9A1712A6124…>
console.log(SHA2.sha512(input)); // Uint8Array <5E1524B5E36A7EDC30BB1497C1B8…>
console.log(SHA2.sha512_224(input)); // Buffer <A7EFE64AF983FB678ACBDEE406072F…>
console.log(SHA2.sha512_256(input)); // Buffer <18EB999808D6CC5B52191F79CD1576…>
console.log(SHA2.sha512_t(80, input)); // Buffer <2626982C7F4477C2B13E>
console.log(Buffer.isBuffer(SHA2.sha224(input))); // true
console.log(Buffer.isBuffer(SHA2.sha256(input))); // true
console.log(Buffer.isBuffer(SHA2.sha384(input))); // true
console.log(Buffer.isBuffer(SHA2.sha512(input))); // true
console.log(Buffer.isBuffer(SHA2.sha512_224(input))); // true
console.log(Buffer.isBuffer(SHA2.sha512_256(input))); // true
console.log(Buffer.isBuffer(SHA2.sha512_t(80, input))); // true

#2

We use v8’s GetConstructorName to determine the name of the class. I believe that Buffer’s unique implementation (where it is an instance of Uint8Array: https://nodejs.org/api/buffer.html#buffer_buffers_and_typedarray ) is possibly confusing v8. Will look into it further.