| Total Complexity | 4 |
| Complexity/F | 2 |
| Lines of Code | 30 |
| Function Count | 2 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import * as fs from 'fs' |
||
| 2 | import { Id3TagStreamProcessor } from './file-stream-processor' |
||
| 3 | import { processFileSync, processFileAsync, fsReadAsync } from './util-file' |
||
| 4 | |||
| 5 | export function getId3TagDataFromFileSync(filepath: string) { |
||
| 6 | const reader = new Id3TagStreamProcessor(12) |
||
| 7 | processFileSync(filepath, 'r', (fileDescriptor) => { |
||
| 8 | do { |
||
| 9 | const readBuffer = reader.getReadBuffer() |
||
| 10 | const sizeRead = fs.readSync(fileDescriptor, readBuffer) |
||
| 11 | const missingData = reader.processReadBuffer(sizeRead) |
||
| 12 | fs.readSync(fileDescriptor, missingData) |
||
| 13 | } while(reader.continue) |
||
| 14 | }) |
||
| 15 | return reader.getTags() |
||
| 16 | } |
||
| 17 | |||
| 18 | export async function getId3TagDataFromFileAsync(filepath: string) { |
||
| 19 | const reader = new Id3TagStreamProcessor(12) |
||
| 20 | await processFileAsync(filepath, 'r', async (fileDescriptor) => { |
||
| 21 | do { |
||
| 22 | const readBuffer = reader.getReadBuffer() |
||
| 23 | const sizeRead = await fsReadAsync(fileDescriptor, readBuffer) |
||
| 24 | const missingData = reader.processReadBuffer(sizeRead) |
||
| 25 | await fsReadAsync(fileDescriptor, missingData) |
||
| 26 | } while(reader.continue) |
||
| 27 | }) |
||
| 28 | return reader.getTags() |
||
| 29 | } |
||
| 30 |