Skip to content

Commit fd5b0e0

Browse files
committed
docs: add usage documentation for data access, resource management, and tags
1 parent d449ffe commit fd5b0e0

3 files changed

Lines changed: 71 additions & 0 deletions

File tree

docs/usage/data.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Data
2+
3+
There are three ways to access the data of an `ExifEntry`.
4+
5+
1. `toString()`
6+
7+
`toString()` internally calls `exif_entry_get_value()` and returns a string. This will be context dependent (i.e. tag-aware). It's most useful for `ASCII` types or for human usage.
8+
9+
2. `.data`
10+
11+
`.data` returns the `ExifEntry`'s data as a Uint8Array. Since it is using the buffer's byte order rather than the byte order of the `ExifEntry` (see [byte-order.md](byte-order.md)), this may be difficult to manipulate or read, but it is the most direct access to the `ExifEntry`'s data. It is indepdenent of format, tag, and byte order.
12+
13+
One note is that when updating it, the previous `.data` will be freed automatically. Furthermore, while `.size` will be updated for you, `.components` will not, and you will have to update it yourself.
14+
15+
3. `toTypedArray`/`fromTypedArray`
16+
17+
These methods did not exist in the original API. They require both the format and the byte order to have already been set correctly. However, they internally use the utility functions that read libexif data structures in `exifUtils.ts` to ensure the data is interepreted properly. The output is based on the format, being:
18+
19+
- ASCII, UNDEFINED, BYTE: Uint8Array
20+
- SBYTE: Int8Array
21+
- SHORT: Uint16Array
22+
- SSHORT: Int16Array
23+
- LONG, RATIONAL: Uint32Array
24+
- SLONG, SRATIONAL: Int32Array
25+
26+
If using `fromTypedArray`, the input typedArray will be converted to the correct byte order.
27+
28+
Since RATIONAL and SRATIONAL return a TypedArray for convenience, if one wants to convert them into rational objects with numerator and denominators, `mapRationalFromObject` and `mapRationalToObject` exist.
29+
30+
Unlike `.data`, `.components` will be set for you.

docs/usage/resource-management.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Resource Management
2+
3+
By default, most classes implement the the TypeScript `Disposable` interface, which uses the [`Symbol.dispose` well-known symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/dispose). Hence, for those using TypeScript or in browsers that support it, one can use the [`using`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/using) keyword to automatically clean up any memory allocated.
4+
5+
```ts
6+
using exifData = ExifData.from(data);
7+
// Cleaned up automatically after use
8+
```
9+
10+
Suppose you intend on interacting with a resource from one of these classes. You should generally do it like this:
11+
12+
```ts
13+
using exifData = ExifData.from(data);
14+
const exifContent = exifData.ifd[0];
15+
```
16+
17+
This is because when `exifData.free()` is ran, it automatically frees the resources it relies on, including its exifContent IFD memory allocations.
18+
19+
However, if you intend on changing it, you will need to free the one you are no longer using:
20+
21+
```ts
22+
using exifData = ExifData.from(data);
23+
const exifContent = ExifContent.new();
24+
const prevExifContent = exifData.ifd[0];
25+
exifContent.ifd = exifContent.ifd.with(0, exifContent);
26+
prevExifContent.free();
27+
```
28+
29+
The generally holds true for most data structures in this library, with the exception of ExifEntry.data, which will automatically free itself.

docs/usage/tags.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Tags
2+
3+
Tags are represented by two enums: `ExifTag` and `ExifTagGps`. For simplicity, these are merged into the enum `ExifTagUnified`. You can generally use it the same way you would any other enum with the exception of four tags:
4+
5+
- `LATITUDE_REF`: 1
6+
- `INTEROPERABILITY_INDEX`: 1
7+
- `LATITUDE`: 2
8+
- `INTEROPERABILITY_VERSION`: 2
9+
10+
These tags have different meanings in different ifds.
11+
12+
`.tagVal` is avaliable in `ExifEntry` if one needs the value directly. Alternatively, `getExifTagTable` also offers the whole array of `TagEntry[]` with their tag value, name, title, description, and support level, if necessary.

0 commit comments

Comments
 (0)