diff --git a/src/index.test.ts b/src/index.test.ts index 8dbfda9..56b4c62 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -41,8 +41,8 @@ describe('chardet', () => { expect(res).toBe('UTF-8'); }); - it('should detect encoding with smaller sample size and position offset', async () => { - const res = await chardet.detectFile(path, { sampleSize: 32, position: 64 }); + it('should detect encoding with smaller sample size and offset', async () => { + const res = await chardet.detectFile(path, { sampleSize: 32, offset: 64 }); expect(res).toBe('UTF-8'); }); }); @@ -56,8 +56,8 @@ describe('chardet', () => { expect(chardet.detectFileSync(path, { sampleSize: 32 })).toBe('UTF-8'); }); - it('should detect encoding with smaller sample size and position offset', () => { - expect(chardet.detectFileSync(path, { sampleSize: 32, position: 64 })).toBe('UTF-8'); + it('should detect encoding with smaller sample size and offset', () => { + expect(chardet.detectFileSync(path, { sampleSize: 32, offset: 64 })).toBe('UTF-8'); }); }); diff --git a/src/index.ts b/src/index.ts index d6e5fc7..a43ade3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,7 @@ import * as iso2022 from './encoding/iso2022'; interface FullOptions { sampleSize: number, - position: number + offset: number } type Options = Partial @@ -108,7 +108,7 @@ export const detectFile = (filepath: string, opts: Options = {}): Promise { + fs.read(fd, sample, 0, opts.sampleSize, opts.offset, (err?: Error) => { handler(err, sample); }); return; @@ -124,7 +124,7 @@ export const detectFileSync = (filepath: string, opts: Options = {}): DetectResu const fd = fs.openSync(filepath, 'r'); const sample = Buffer.allocUnsafe(opts.sampleSize); - fs.readSync(fd, sample, 0, opts.sampleSize, opts.position); + fs.readSync(fd, sample, 0, opts.sampleSize, opts.offset); fs.closeSync(fd); return detect(sample); }