PeculiarVentures / asn1-schema

asn1-schema is a collection of TypeScript schemas that make working with common ASN.1 objects easy
33 stars 11 forks source link

ReadableStream support for BufferSource? #86

Open Manouchehri opened 1 year ago

Manouchehri commented 1 year ago

Would it be possible to have things like AsnParser.parse(...) support ReadableStream as the data BufferSource?

e.g.

import { AsnParser } from "@peculiar/asn1-schema";
import { Certificate } from "@peculiar/asn1-x509";

fetch("https://raw.githubusercontent.com/google/clusterfuzz/master/docs/setting-up-fuzzing/heartbleed/server.pem").then(async current_response => {
    const cert = AsnParser.parse(current_response.body, Certificate);
    console.log(cert);
})

instead of:

import { AsnParser } from "@peculiar/asn1-schema";
import { Certificate } from "@peculiar/asn1-x509";

fetch("https://raw.githubusercontent.com/google/clusterfuzz/master/docs/setting-up-fuzzing/heartbleed/server.pem").then(async current_response => {
    const cert = AsnParser.parse(await current_response.arrayBuffer(), Certificate);
    console.log(cert);
})

While this simplified example only has a tiny certificate, I think ReadableStream would help reduce memory and decoding times for very large BER buffers.