How to use the token-types.StringType function in token-types

To help you get started, we’ve selected a few token-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sindresorhus / file-type / core.js View on Github external
if (zipHeader.filename.startsWith('xl/')) {
				return {
					ext: 'xlsx',
					mime: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
				};
			}

			// The docx, xlsx and pptx file types extend the Office Open XML file format:
			// https://en.wikipedia.org/wiki/Office_Open_XML_file_formats
			// We look for:
			// - one entry named '[Content_Types].xml' or '_rels/.rels',
			// - one entry indicating specific type of file.
			// MS Office, OpenOffice and LibreOffice may put the parts in different order, so the check should not rely on it.
			if (zipHeader.filename === 'mimetype' && zipHeader.compressedSize === zipHeader.uncompressedSize) {
				const mimeType = await tokenizer.readToken(new Token.StringType(zipHeader.compressedSize, 'utf-8'));

				switch (mimeType) {
					case 'application/epub+zip':
						return {
							ext: 'epub',
							mime: 'application/epub+zip'
						};
					case 'application/vnd.oasis.opendocument.text':
						return {
							ext: 'odt',
							mime: 'application/vnd.oasis.opendocument.text'
						};
					case 'application/vnd.oasis.opendocument.spreadsheet':
						return {
							ext: 'ods',
							mime: 'application/vnd.oasis.opendocument.spreadsheet'
github Borewit / music-metadata / src / ogg.ts View on Github external
return this.tokenizer.readToken(Token.UINT32_LE).then((strLen) => {
      return this.tokenizer.readToken(new Token.StringType(strLen, 'ascii')).then((v) => {
        const idx = v.indexOf('=');
        const key = v.slice(0, idx).toUpperCase();
        let value: any = v.slice(idx + 1);

        if (key === 'METADATA_BLOCK_PICTURE') {
          value = this.options.skipCovers ? null : VorbisPictureToken.fromBase64(value);
        }

        if (value !== null)
          this.tags.push({id: key, value});

        const len = Token.UINT32_LE.len + strLen;
        if (--userCommentListLength > 0) {
          // if we don't want to read the duration
          // then tell the parent stream to stop
          // stop = !readDuration;
github Borewit / music-metadata / lib / apev2 / APEv2Token.ts View on Github external
get: (buf, off) => {
    return {
      // should equal 'APETAGEX'
      ID: new Token.StringType(8, 'ascii').get(buf, off),
      // equals CURRENT_APE_TAG_VERSION
      version: Token.UINT32_LE.get(buf, off + 8),
      // the complete size of the tag, including this footer (excludes header)
      size: Token.UINT32_LE.get(buf, off + 12),
      // the number of fields in the tag
      fields: Token.UINT32_LE.get(buf, off + 16),
      // reserved for later use (must be zero),
      flags: parseTagFlags(Token.UINT32_LE.get(buf, off + 20))
    };
  }
};
github Borewit / music-metadata / lib / ogg / vorbis / Vorbis.ts View on Github external
get: (buf, off): ICommonHeader => {
    return {
      packetType: buf.readUInt8(off),
      vorbis: new Token.StringType(6, 'ascii').get(buf, off + 1)
    };
  }
};
github Borewit / music-metadata / lib / riff / RiffChunk.ts View on Github external
public get(buf, off): string {
    return new Token.StringType(this.tagHeader.chunkSize, 'ascii').get(buf, off);
  }
}
github Borewit / music-metadata / lib / mp4 / AtomToken.ts View on Github external
get: (buf: Buffer, off: number): IAtomFtyp => {
    return {
      type: new Token.StringType(4, 'ascii').get(buf, off)
    };
  }
};
github Borewit / music-metadata / lib / mp4 / AtomToken.ts View on Github external
public get(buf: Buffer, off: number): INameAtom {
    return {
      version: Token.UINT8.get(buf, off),
      flags: Token.UINT24_BE.get(buf, off + 1),
      name: new Token.StringType(this.len - 4, 'utf-8').get(buf, off + 4)
    };
  }
}
github Borewit / music-metadata / lib / ogg / speex / Speex.ts View on Github external
get: (buf, off) => {

    return {
      speex: new Token.StringType(8, 'ascii').get(buf, off + 0),
      version: BitUtil.trimRightNull(new Token.StringType(20, 'ascii').get(buf, off + 8)),
      version_id: buf.readInt32LE(off + 28),
      header_size: buf.readInt32LE(off + 32),
      rate: buf.readInt32LE(off + 36),
      mode: buf.readInt32LE(off + 40),
      mode_bitstream_version: buf.readInt32LE(off + 44),
      nb_channels: buf.readInt32LE(off + 48),
      bitrate: buf.readInt32LE(off + 52),
      frame_size: buf.readInt32LE(off + 56),
      vbr: buf.readInt32LE(off + 60),
      frames_per_packet: buf.readInt32LE(off + 64),
      extra_headers: buf.readInt32LE(off + 68),
      reserved1: buf.readInt32LE(off + 72),
      reserved2: buf.readInt32LE(off + 76)
    };
  }
};
github Borewit / music-metadata / src / ogg.ts View on Github external
return this.tokenizer.readToken(Token.UINT32_LE).then((strLen) => {
      return this.tokenizer.readToken(new Token.StringType(strLen, 'utf-8')).then((vendorString: string) => {
        return this.tokenizer.readToken(Token.UINT32_LE).then((userCommentListLength) => {
          return this.parseUserComment(userCommentListLength).then((len) => {
            return 2 * Token.UINT32_LE.len + strLen + len;
          });
        });
      });
    });
  }
github Borewit / music-metadata / lib / ogg / theora / Theora.ts View on Github external
get: (buf, off): IIdentificationHeader => {
    return {
      id: new Token.StringType(7, 'ascii').get(buf, off),
      vmaj: buf.readUInt8(off + 7),
      vmin: buf.readUInt8(off + 8),
      vrev: buf.readUInt8(off + 9),
      vmbw: buf.readUInt16BE(off + 10),
      vmbh: buf.readUInt16BE(off + 17),
      nombr: Token.UINT24_BE.get(buf, off + 37),
      nqual: buf.readUInt8(off + 40)
    };
  }
};