How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • // In an `async` function
    // In an `async` function
    await csvWriter.writeRecords(records1)
    await csvWriter.writeRecords(records2)
    ...
    Docs
  • var asn1 = forge.asn1;
     
    // create a SubjectPublicKeyInfo
    // create a SubjectPublicKeyInfo
    var subjectPublicKeyInfo =
      asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
        // AlgorithmIdentifier
    // AlgorithmIdentifier
        asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
          // algorithm
    // algorithm
          asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
            asn1.oidToDer(pki.oids['rsaEncryption']).getBytes()),
          // parameters (null)
    // parameters (null)
          asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')
        ]),
        // subjectPublicKey
    // subjectPublicKey
        asn1.create(asn1.Class.UNIVERSAL, asn1.Type.BITSTRING, false, [
          // RSAPublicKey
    // RSAPublicKey
          asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
            // modulus (n)
    // modulus (n)
            asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
              _bnToBytes(key.n)),
            // publicExponent (e)
    // publicExponent (e)
            asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
              _bnToBytes(key.e))
          ])
        ])
      ]);
     
    // serialize an ASN.1 object to DER format
    // serialize an ASN.1 object to DER format
    var derBuffer = asn1.toDer(subjectPublicKeyInfo);
     
    // deserialize to an ASN.1 object from a byte buffer filled with DER data
    // deserialize to an ASN.1 object from a byte buffer filled with DER data
    var object = asn1.fromDer(derBuffer);
     
    // convert an OID dot-separated string to a byte buffer
    // convert an OID dot-separated string to a byte buffer
    var derOidBuffer = asn1.oidToDer('1.2.840.113549.1.1.5');
     
    // convert a byte buffer with a DER-encoded OID to a dot-separated string
    // convert a byte buffer with a DER-encoded OID to a dot-separated string
    console.log(asn1.derToOid(derOidBuffer));
    // output: 1.2.840.113549.1.1.5
    // output: 1.2.840.113549.1.1.5
     
    // validates that an ASN.1 object matches a particular ASN.1 structure and
    // validates that an ASN.1 object matches a particular ASN.1 structure and
    // captures data of interest from that structure for easy access
    // captures data of interest from that structure for easy access
    var publicKeyValidator = {
      name: 'SubjectPublicKeyInfo',
      tagClass: asn1.Class.UNIVERSAL,
      type: asn1.Type.SEQUENCE,
      constructed: true,
      captureAsn1: 'subjectPublicKeyInfo',
      value: [{
        name: 'SubjectPublicKeyInfo.AlgorithmIdentifier',
        tagClass: asn1.Class.UNIVERSAL,
        type: asn1.Type.SEQUENCE,
        constructed: true,
        value: [{
          name: 'AlgorithmIdentifier.algorithm',
          tagClass: asn1.Class.UNIVERSAL,
          type: asn1.Type.OID,
          constructed: false,
          capture: 'publicKeyOid'
        }]
      }, {
        // subjectPublicKey
    // subjectPublicKey
        name: 'SubjectPublicKeyInfo.subjectPublicKey',
        tagClass: asn1.Class.UNIVERSAL,
        type: asn1.Type.BITSTRING,
        constructed: false,
        value: [{
          // RSAPublicKey
    // RSAPublicKey
          name: 'SubjectPublicKeyInfo.subjectPublicKey.RSAPublicKey',
          tagClass: asn1.Class.UNIVERSAL,
          type: asn1.Type.SEQUENCE,
          constructed: true,
          optional: true,
          captureAsn1: 'rsaPublicKey'
        }]
      }]
    };
     
    var capture = {};
    var errors = [];
    if(!asn1.validate(
      publicKeyValidator, subjectPublicKeyInfo, validator, capture, errors)) {
      throw 'ASN.1 object is not a SubjectPublicKeyInfo.';
    }
    // capture.subjectPublicKeyInfo contains the full ASN.1 object
    // capture.subjectPublicKeyInfo contains the full ASN.1 object
    // capture.rsaPublicKey contains the full ASN.1 object for the RSA public key
    // capture.rsaPublicKey contains the full ASN.1 object for the RSA public key
    // capture.publicKeyOid only contains the value for the OID
    // capture.publicKeyOid only contains the value for the OID
    var oid = asn1.derToOid(capture.publicKeyOid);
    if(oid !== pki.oids['rsaEncryption']) {
      throw 'Unsupported OID.';
    }
     
    // pretty print an ASN.1 object to a string for debugging purposes
    // pretty print an ASN.1 object to a string for debugging purposes
    asn1.prettyPrint(object);
    Docs
  • const encoder = new TextEncoder();
    const writer = port.writable.getWriter();
    await writer.write(encoder.encode("PING"));
    writer.releaseLock();
    
    Docs
  • const writer = getWritableStreamSomehow();
    for (let i = 0; i < 100; i++) {
      writer.write(`hello, #${i}!\n`);
    }
    writer.on('finish', () => {
      console.log('All writes are now complete.');
    });
    writer.end('This is the end\n');
    Docs
  • import {
      WritableStream
    } from 'node:stream/web';
    
    const stream = new WritableStream({
      write(chunk) {
        console.log(chunk);
      }
    });
    
    await stream.getWriter().write('Hello World');
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples