Skip to content

Commit 88a70f5

Browse files
committed
split src/highlevel-api.js into multiple files in src/highlevel/ dir; moved highlevel-* tests to tests/highglevel/
1 parent 546808f commit 88a70f5

File tree

8 files changed

+85
-77
lines changed

8 files changed

+85
-77
lines changed

src/bundles/mini.mjs

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import * as nano from './nano.mjs'
33
export default nano
44

55

6-
// Highlevel API orientation, rotation, gps, thumbnail
7-
export * from '../highlevel-api.mjs'
6+
// Highlevel API: gps(), thumbnail(), thumbnailUrl(), orientation(), rotation()
7+
export * from '../highlevel/gps.mjs'
8+
export * from '../highlevel/thumb.mjs'
9+
export * from '../highlevel/orientation.mjs'
810

911
// File Readers
1012
import '../file-readers/BlobReader.mjs'

src/highlevel/disableAllOptions.mjs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const disableAllOptions = {
2+
ifd0: false,
3+
ifd1: false,
4+
exif: false,
5+
gps: false,
6+
interop: false,
7+
// turning off all unnecessary steps and transformation to get the needed data ASAP
8+
sanitize: false,
9+
reviveValues: true,
10+
translateKeys: false,
11+
translateValues: false,
12+
mergeOutput: false,
13+
}

src/highlevel/gps.mjs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {Exifr} from '../Exifr.mjs'
2+
import {TAG_GPS_LATREF, TAG_GPS_LAT, TAG_GPS_LONREF, TAG_GPS_LON} from '../tags.mjs'
3+
import {disableAllOptions} from './disableAllOptions.mjs'
4+
5+
6+
export const gpsOnlyOptions = Object.assign({}, disableAllOptions, {
7+
firstChunkSize: 40000,
8+
gps: [TAG_GPS_LATREF, TAG_GPS_LAT, TAG_GPS_LONREF, TAG_GPS_LON],
9+
})
10+
11+
export async function gps(input) {
12+
let exr = new Exifr(gpsOnlyOptions)
13+
await exr.read(input)
14+
let output = await exr.parse()
15+
if (output && output.gps) {
16+
let {latitude, longitude} = output.gps
17+
return {latitude, longitude}
18+
}
19+
}

src/highlevel-api.mjs src/highlevel/orientation.mjs

+3-61
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,13 @@
1-
// High level API.
2-
import * as platform from './util/platform.mjs'
3-
import {Buffer} from './util/platform.mjs'
4-
import {Exifr} from './Exifr.mjs'
5-
import {TAG_GPS_LATREF, TAG_GPS_LAT, TAG_GPS_LONREF, TAG_GPS_LON, TAG_ORIENTATION} from './tags.mjs'
1+
import {Exifr} from '../Exifr.mjs'
2+
import {TAG_ORIENTATION} from '../tags.mjs'
3+
import {disableAllOptions} from './disableAllOptions.mjs'
64

75

8-
export const disableAllOptions = {
9-
ifd0: false,
10-
ifd1: false,
11-
exif: false,
12-
gps: false,
13-
interop: false,
14-
// turning off all unnecessary steps and transformation to get the needed data ASAP
15-
sanitize: false,
16-
reviveValues: true,
17-
translateKeys: false,
18-
translateValues: false,
19-
mergeOutput: false,
20-
}
21-
22-
export const gpsOnlyOptions = Object.assign({}, disableAllOptions, {
23-
firstChunkSize: 40000,
24-
gps: [TAG_GPS_LATREF, TAG_GPS_LAT, TAG_GPS_LONREF, TAG_GPS_LON],
25-
})
26-
276
export const orientationOnlyOptions = Object.assign({}, disableAllOptions, {
287
firstChunkSize: 40000,
298
ifd0: [TAG_ORIENTATION],
309
})
3110

32-
export const thumbnailOnlyOptions = Object.assign({}, disableAllOptions, {
33-
tiff: false,
34-
ifd1: true,
35-
// needed to prevent options from disabling ifd1
36-
mergeOutput: false
37-
})
38-
39-
40-
export async function thumbnail(input) {
41-
let exr = new Exifr(thumbnailOnlyOptions)
42-
await exr.read(input)
43-
let u8arr = await exr.extractThumbnail()
44-
if (u8arr && platform.hasBuffer)
45-
return Buffer.from(u8arr)
46-
else
47-
return u8arr
48-
}
49-
50-
// only available in browser
51-
export async function thumbnailUrl(input) {
52-
let u8arr = await this.thumbnail(input)
53-
if (u8arr !== undefined) {
54-
let blob = new Blob([u8arr]) // note: dont use AB directly, because of byteOffset
55-
return URL.createObjectURL(blob)
56-
}
57-
}
58-
59-
export async function gps(input) {
60-
let exr = new Exifr(gpsOnlyOptions)
61-
await exr.read(input)
62-
let output = await exr.parse()
63-
if (output && output.gps) {
64-
let {latitude, longitude} = output.gps
65-
return {latitude, longitude}
66-
}
67-
}
68-
6911
export async function orientation(input) {
7012
let exr = new Exifr(orientationOnlyOptions)
7113
await exr.read(input)

src/highlevel/thumb.mjs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as platform from '../util/platform.mjs'
2+
import {Buffer} from '../util/platform.mjs'
3+
import {Exifr} from '../Exifr.mjs'
4+
import {disableAllOptions} from './disableAllOptions.mjs'
5+
6+
7+
export const thumbnailOnlyOptions = Object.assign({}, disableAllOptions, {
8+
tiff: false,
9+
ifd1: true,
10+
// needed to prevent options from disabling ifd1
11+
mergeOutput: false
12+
})
13+
14+
15+
export async function thumbnail(input) {
16+
let exr = new Exifr(thumbnailOnlyOptions)
17+
await exr.read(input)
18+
let u8arr = await exr.extractThumbnail()
19+
if (u8arr && platform.hasBuffer)
20+
return Buffer.from(u8arr)
21+
else
22+
return u8arr
23+
}
24+
25+
// only available in browser
26+
export async function thumbnailUrl(input) {
27+
let u8arr = await this.thumbnail(input)
28+
if (u8arr !== undefined) {
29+
let blob = new Blob([u8arr]) // note: dont use AB directly, because of byteOffset
30+
return URL.createObjectURL(blob)
31+
}
32+
}

test/highlevel-gps.spec.mjs test/highlevel/gps.spec.mjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {assert} from './test-util-core.mjs'
2-
import {getFile} from './test-util-core.mjs'
3-
import {Exifr} from '../src/bundles/full.mjs'
4-
import * as exifr from '../src/bundles/full.mjs'
5-
import {gpsOnlyOptions} from '../src/highlevel-api.mjs'
1+
import {assert} from '../test-util-core.mjs'
2+
import {getFile} from '../test-util-core.mjs'
3+
import {Exifr} from '../../src/bundles/full.mjs'
4+
import * as exifr from '../../src/bundles/full.mjs'
5+
import {gpsOnlyOptions} from '../../src/highlevel/gps.mjs'
66

77

88
describe('exifr.gps()', () => {

test/highlevel-orientation.spec.mjs test/highlevel/orientation.spec.mjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {assert, isNode} from './test-util-core.mjs'
2-
import {getFile} from './test-util-core.mjs'
3-
import {Exifr} from '../src/bundles/full.mjs'
4-
import * as exifr from '../src/bundles/full.mjs'
5-
import {orientationOnlyOptions} from '../src/highlevel-api.mjs'
1+
import {assert, isNode} from '../test-util-core.mjs'
2+
import {getFile} from '../test-util-core.mjs'
3+
import {Exifr} from '../../src/bundles/full.mjs'
4+
import * as exifr from '../../src/bundles/full.mjs'
5+
import {orientationOnlyOptions} from '../../src/highlevel/orientation.mjs'
66

77

88
describe('exifr.orientation()', () => {

test/highlevel-thumb.spec.mjs test/highlevel/thumb.spec.mjs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {assert} from './test-util-core.mjs'
2-
import {getFile, getPath, isNode, isBrowser} from './test-util-core.mjs'
3-
import {Exifr} from '../src/bundles/full.mjs'
4-
import * as exifr from '../src/bundles/full.mjs'
1+
import {assert} from '../test-util-core.mjs'
2+
import {getFile, getPath, isNode, isBrowser} from '../test-util-core.mjs'
3+
import {Exifr} from '../../src/bundles/full.mjs'
4+
import * as exifr from '../../src/bundles/full.mjs'
55

66

77
describe('thumbnail', () => {

0 commit comments

Comments
 (0)