Rename position -> offset

This commit is contained in:
Eliott Vincent 2022-10-07 10:15:10 +02:00
parent 40b87b49d7
commit d085d275b3
2 changed files with 7 additions and 7 deletions

View File

@ -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');
});
});

View File

@ -11,7 +11,7 @@ import * as iso2022 from './encoding/iso2022';
interface FullOptions {
sampleSize: number,
position: number
offset: number
}
type Options = Partial<FullOptions>
@ -108,7 +108,7 @@ export const detectFile = (filepath: string, opts: Options = {}): Promise<Detect
fd = fs.openSync(filepath, 'r');
const sample: Buffer = Buffer.allocUnsafe(opts.sampleSize);
fs.read(fd, sample, 0, opts.sampleSize, opts.position, (err?: Error) => {
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);
}