Blockchain Commons Uniform Resources TypeScript Library - v1.0.0-alpha.13
    Preparing search index...

    Class MultipartEncoder

    Encodes a UR as multiple parts using fountain codes.

    This allows large CBOR structures to be split into multiple UR strings that can be transmitted separately and reassembled. The encoder uses fountain codes for resilient transmission over lossy channels.

    For single-part URs (small payloads), use the regular UR.string() method.

    const ur = UR.new('bytes', cbor);
    const encoder = new MultipartEncoder(ur, 100);

    // Generate all pure parts
    while (!encoder.isComplete()) {
    const part = encoder.nextPart();
    console.log(part); // "ur:bytes/1-10/..."
    }

    // Generate additional rateless parts for redundancy
    for (let i = 0; i < 5; i++) {
    const part = encoder.nextPart();
    console.log(part); // "ur:bytes/11-10/..."
    }
    Index

    Constructors

    • Creates a new multipart encoder for the given UR.

      Parameters

      • ur: UR

        The UR to encode

      • maxFragmentLen: number

        Maximum length of each fragment in bytes

      Returns MultipartEncoder

      If encoding fails

      const encoder = new MultipartEncoder(ur, 100);
      

    Methods

    • Gets the next part of the encoding.

      Parts 1 through seqLen are "pure" fragments containing one piece each. Parts beyond seqLen are "mixed" fragments using fountain codes for redundancy.

      Returns string

      The next UR string part

      const part = encoder.nextPart();
      // Returns: "ur:bytes/1-3/lsadaoaxjygonesw"
    • Gets the total number of pure parts.

      Note: Fountain codes can generate unlimited parts beyond this count for additional redundancy.

      Returns number