@eris/exif
Advanced tools
Comparing version 0.4.2-alpha.12 to 0.4.2-alpha.13
@@ -18,3 +18,5 @@ /// <reference types="node" /> | ||
extractIFDEntries(): IIFDEntry[]; | ||
static injectMetadataIntoJPEG(jpeg: IBufferLike, metadata: IGenericMetadata): IBufferLike; | ||
static isLikelyTIFF(buffer: IBufferLike): boolean; | ||
static replaceIFDEntry(decoder: TIFFDecoder, tag: IFDTagName, data: Buffer): Buffer; | ||
} |
@@ -146,8 +146,3 @@ "use strict"; | ||
const metadata = this.extractMetadata(); | ||
delete metadata.ImageWidth; | ||
delete metadata.ImageLength; | ||
delete metadata.EXIFImageWidth; | ||
delete metadata.EXIFImageHeight; | ||
const metadataBuffer = tiff_encoder_1.TIFFEncoder.encode(metadata); | ||
this._cachedJPEG = jpeg_decoder_1.JPEGDecoder.injectEXIFMetadata(jpeg, metadataBuffer); | ||
this._cachedJPEG = TIFFDecoder.injectMetadataIntoJPEG(jpeg, metadata); | ||
return this._cachedJPEG.slice(); | ||
@@ -179,2 +174,14 @@ } | ||
} | ||
static injectMetadataIntoJPEG(jpeg, metadata) { | ||
const metadataToInject = Object.assign({}, metadata); | ||
delete metadataToInject.ImageWidth; | ||
delete metadataToInject.ImageLength; | ||
delete metadataToInject.EXIFImageWidth; | ||
delete metadataToInject.EXIFImageHeight; | ||
const metadataBuffer = tiff_encoder_1.TIFFEncoder.encode(metadataToInject); | ||
return jpeg_decoder_1.JPEGDecoder.injectEXIFMetadata(jpeg, metadataBuffer); | ||
} | ||
static isLikelyTIFF(buffer) { | ||
return (buffer[0] === 0x49 && buffer[1] === 0x49) || (buffer[0] === 0x4d && buffer[1] === 0x4d); | ||
} | ||
static replaceIFDEntry(decoder, tag, data) { | ||
@@ -181,0 +188,0 @@ const ifd = decoder.extractIFDEntries().find(ifd => tags_1.getFriendlyName(ifd.tag) === tag); |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.FujiDecoder = fuji_decoder_1.FujiDecoder; | ||
const cr3_decoder_1 = require("./decoder/cr3-decoder"); | ||
const tiff_decoder_1 = require("./decoder/tiff-decoder"); | ||
@@ -21,5 +22,2 @@ exports.TIFFDecoder = tiff_decoder_1.TIFFDecoder; | ||
} | ||
function isLikelyTIFF(buffer) { | ||
return (buffer[0] === 0x49 && buffer[1] === 0x49) || (buffer[0] === 0x4d && buffer[1] === 0x4d); | ||
} | ||
function isLikelyFuji(buffer) { | ||
@@ -39,3 +37,6 @@ for (let i = 0; i < fuji_decoder_1.FUJI_MAGIC_STRING.length; i++) { | ||
} | ||
else if (isLikelyTIFF(bufferOrDecoder)) { | ||
else if (cr3_decoder_1.Cr3Decoder.isLikelyCr3(bufferOrDecoder)) { | ||
return new cr3_decoder_1.Cr3Decoder(bufferOrDecoder); | ||
} | ||
else if (tiff_decoder_1.TIFFDecoder.isLikelyTIFF(bufferOrDecoder)) { | ||
return new tiff_decoder_1.TIFFDecoder(bufferOrDecoder); | ||
@@ -42,0 +43,0 @@ } |
@@ -15,2 +15,3 @@ import { IBufferLike, IReader, Endian } from '../utils/types'; | ||
readAsString(length: number): string; | ||
readAsHex(length: number): string; | ||
readAsBuffer(length: number): IBufferLike; | ||
@@ -17,0 +18,0 @@ readAsReader(length: number): IReader; |
@@ -42,6 +42,16 @@ "use strict"; | ||
readAsString(length) { | ||
const value = this._buffer.slice(this._position, this._position + length); | ||
this._position += length; | ||
return value.toString(); | ||
return this.readAsBuffer(length).toString(); | ||
} | ||
readAsHex(length) { | ||
const maxChunkLength = 2; | ||
const chunks = []; | ||
for (let i = 0; i < length; i += maxChunkLength) { | ||
const chunkLength = Math.min(maxChunkLength, length - i); | ||
let chunk = this.read(chunkLength).toString(16); | ||
while (chunk.length < chunkLength * 2) | ||
chunk = `0${chunk}`; | ||
chunks.push(chunk); | ||
} | ||
return this._endianness === types_1.Endian.Big ? chunks.join('') : chunks.reverse().join(''); | ||
} | ||
readAsBuffer(length) { | ||
@@ -48,0 +58,0 @@ const value = this._buffer.slice(this._position, this._position + length); |
@@ -20,2 +20,3 @@ /// <reference types="node" /> | ||
readAsString(length: number): string; | ||
readAsHex(length: number): string; | ||
readAsBuffer(length: number): IBufferLike; | ||
@@ -22,0 +23,0 @@ readAsReader(length: number): IReader; |
@@ -187,9 +187,3 @@ import {IFD} from '../decoder/ifd' | ||
const metadata = this.extractMetadata() | ||
delete metadata.ImageWidth | ||
delete metadata.ImageLength | ||
delete metadata.EXIFImageWidth | ||
delete metadata.EXIFImageHeight | ||
const metadataBuffer = TIFFEncoder.encode(metadata) | ||
this._cachedJPEG = JPEGDecoder.injectEXIFMetadata(jpeg, metadataBuffer) | ||
this._cachedJPEG = TIFFDecoder.injectMetadataIntoJPEG(jpeg, metadata) | ||
return this._cachedJPEG.slice() | ||
@@ -226,2 +220,16 @@ } | ||
public static injectMetadataIntoJPEG(jpeg: IBufferLike, metadata: IGenericMetadata): IBufferLike { | ||
const metadataToInject = {...metadata} | ||
delete metadataToInject.ImageWidth | ||
delete metadataToInject.ImageLength | ||
delete metadataToInject.EXIFImageWidth | ||
delete metadataToInject.EXIFImageHeight | ||
const metadataBuffer = TIFFEncoder.encode(metadataToInject) | ||
return JPEGDecoder.injectEXIFMetadata(jpeg, metadataBuffer) | ||
} | ||
public static isLikelyTIFF(buffer: IBufferLike): boolean { | ||
return (buffer[0] === 0x49 && buffer[1] === 0x49) || (buffer[0] === 0x4d && buffer[1] === 0x4d) | ||
} | ||
public static replaceIFDEntry(decoder: TIFFDecoder, tag: IFDTagName, data: Buffer): Buffer { | ||
@@ -228,0 +236,0 @@ const ifd = decoder.extractIFDEntries().find(ifd => getFriendlyName(ifd.tag) === tag) |
import {JPEGDecoder} from './decoder/jpeg-decoder' | ||
import {FUJI_MAGIC_STRING, FujiDecoder} from './decoder/fuji-decoder' | ||
import {Cr3Decoder} from './decoder/cr3-decoder' | ||
import {TIFFDecoder} from './decoder/tiff-decoder' | ||
@@ -14,6 +15,2 @@ import {XMPDecoder} from './decoder/xmp-decoder' | ||
function isLikelyTIFF(buffer: IBufferLike): boolean { | ||
return (buffer[0] === 0x49 && buffer[1] === 0x49) || (buffer[0] === 0x4d && buffer[1] === 0x4d) | ||
} | ||
function isLikelyFuji(buffer: IBufferLike): boolean { | ||
@@ -32,3 +29,5 @@ for (let i = 0; i < FUJI_MAGIC_STRING.length; i++) { | ||
return new FujiDecoder(bufferOrDecoder) | ||
} else if (isLikelyTIFF(bufferOrDecoder)) { | ||
} else if (Cr3Decoder.isLikelyCr3(bufferOrDecoder)) { | ||
return new Cr3Decoder(bufferOrDecoder) | ||
} else if (TIFFDecoder.isLikelyTIFF(bufferOrDecoder)) { | ||
return new TIFFDecoder(bufferOrDecoder) | ||
@@ -35,0 +34,0 @@ } else if (JPEGDecoder.isJPEG(bufferOrDecoder)) { |
@@ -49,7 +49,18 @@ import {IBufferLike, IReader, Endian} from '../utils/types' | ||
public readAsString(length: number): string { | ||
const value = this._buffer.slice(this._position, this._position + length) | ||
this._position += length | ||
return value.toString() | ||
return this.readAsBuffer(length).toString() | ||
} | ||
public readAsHex(length: number): string { | ||
const maxChunkLength = 2 | ||
const chunks: string[] = [] | ||
for (let i = 0; i < length; i += maxChunkLength) { | ||
const chunkLength = Math.min(maxChunkLength, length - i) | ||
let chunk = this.read(chunkLength).toString(16) | ||
while (chunk.length < chunkLength * 2) chunk = `0${chunk}` | ||
chunks.push(chunk) | ||
} | ||
return this._endianness === Endian.Big ? chunks.join('') : chunks.reverse().join('') | ||
} | ||
public readAsBuffer(length: number): IBufferLike { | ||
@@ -56,0 +67,0 @@ const value = this._buffer.slice(this._position, this._position + length) |
@@ -23,2 +23,3 @@ export interface ILogger { | ||
readAsString(length: number): string | ||
readAsHex(length: number): string | ||
readAsBuffer(length: number): IBufferLike | ||
@@ -25,0 +26,0 @@ readAsReader(length: number): IReader |
{ | ||
"name": "@eris/exif", | ||
"version": "0.4.2-alpha.12", | ||
"version": "0.4.2-alpha.13", | ||
"description": "Parses EXIF data.", | ||
@@ -41,3 +41,3 @@ "main": "./dist/index.js", | ||
}, | ||
"gitHead": "6c902c208d306b02351cb64d2e5e34598215fd74" | ||
"gitHead": "88663db1a984e24d9a12a050161d805be91d8cb6" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
261411
81
4765