Passed
Pull Request — master (#173)
by
unknown
01:49
created

src/file-read.ts   A

Complexity

Total Complexity 4
Complexity/F 2

Size

Lines of Code 30
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 25
mnd 2
bc 2
fnc 2
dl 0
loc 30
rs 10
bpm 1
cpm 2
noi 0
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A file-read.ts ➔ getId3TagDataFromFileSync 0 12 2
A file-read.ts ➔ getId3TagDataFromFileAsync 0 12 2
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