(filePath: string)
| 125 | } |
| 126 | |
| 127 | const ensureValidInputFile = async (filePath: string): Promise<InputFileSpec> => { |
| 128 | const absolutePath = resolve(process.cwd(), filePath) |
| 129 | |
| 130 | if (!fs.existsSync(absolutePath)) { |
| 131 | throw new Error(`Input file does not exist: ${absolutePath}`) |
| 132 | } |
| 133 | |
| 134 | const stats = fs.statSync(absolutePath) |
| 135 | if (!stats.isFile()) { |
| 136 | throw new Error(`Input path is not a file: ${absolutePath}`) |
| 137 | } |
| 138 | |
| 139 | const compressionFormat = await detectCompressionFormat(absolutePath) |
| 140 | |
| 141 | if (compressionFormat) { |
| 142 | const format = inferCompressedFormat(absolutePath) |
| 143 | if (!format) { |
| 144 | throw new Error('Compressed input filename must end with .jsonl.gz, .jsonl.xz, .json.gz, or .json.xz') |
| 145 | } |
| 146 | |
| 147 | return { |
| 148 | absolutePath, |
| 149 | compressionFormat, |
| 150 | format, |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | const extension = extname(absolutePath).toLowerCase() |
| 155 | |
| 156 | if (extension === '.jsonl') { |
| 157 | return { |
| 158 | absolutePath, |
| 159 | format: 'jsonl', |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | if (extension === '.json') { |
| 164 | return { |
| 165 | absolutePath, |
| 166 | format: 'json', |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | throw new Error('Input file must have a .jsonl or .json extension') |
| 171 | } |
| 172 | |
| 173 | const createImportStream = (inputFile: InputFileSpec): NodeJS.ReadableStream => { |
| 174 | const source = fs.createReadStream(inputFile.absolutePath) |
no test coverage detected