license import { ENV } from '@tensorflow/tfjs-core' ; import { DataSource } from '../datasource' ; import { ByteChunkIterator } from '../iterators/byte_chunk_iterator' ; import { FileChunkIterator , FileChunkIteratorOptions } from '../iterators/file_chunk_iterator' ; import { FileElement } from '../types' ; import { isLocalPath } from '../util/source_util' ; /**
 * Represents a file, blob, or Uint8Array readable as a stream of binary data
 * chunks.
 */ export class FileDataSource extends DataSource { param input param options constructor ( protected input , protected readonly options = { } ) { super ( ) ; } async iterator ( ) { if ( isLocalPath ( this . input ) && ENV . get ( 'IS_NODE' ) ) { const fs = require ( 'fs' ) ; this . input = fs . readFileSync ( ( this . input as string ) . substr ( 7 ) ) ; } return new FileChunkIterator ( this . input as FileElement , this . options ) ; } }