Coder Social home page Coder Social logo

Accept buffer input about extractd HOT 4 CLOSED

rad182 avatar rad182 commented on June 13, 2024
Accept buffer input

from extractd.

Comments (4)

przemyslawpluta avatar przemyslawpluta commented on June 13, 2024

@rad182 would your s3 object be a raw file?

from extractd.

rad182 avatar rad182 commented on June 13, 2024

@przemyslawpluta yes. cr2, nef and dng
is this possible?

from extractd.

przemyslawpluta avatar przemyslawpluta commented on June 13, 2024

It could work with accepting buffer, which would be saved as a file and processed to generate preview.

from extractd.

przemyslawpluta avatar przemyslawpluta commented on June 13, 2024

Below should work with exiftool directly ...

const fs = require('fs');
const util = require('util');
const stream = require('stream');
const spawn = require('child_process').spawn;
const temp = require('temp-dir');

const pipeline = util.promisify(stream.pipeline);

const marker = '{ready}';
const terminate = ['-stay_open', 'false'].join('\n');
const action = ['-json', '-JpgFromRaw', '-b', '-', '-execute'].join('\n');

function timeout(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

function stripReadyEnd(done = false) {
    const trans = new stream.Transform({
        transform(chunk, encoding, callback) {
            if (encoding === 'buffer') {
                if (chunk.includes(marker)) {
                    chunk = chunk.slice(0, chunk.indexOf(marker));
                    done = true;
                }
                callback(null, chunk);
                if (done) {
                    trans.end();
                }
            }
        }
    });
    return trans;
}

function streamToExif(target, act, close = false, args = temp + '/args.txt') {
    const argsFile = fs.createWriteStream(args);
    const exiftool = spawn('exiftool', ['-stay_open', 'true', '-@', args]);
    exiftool.stdout.on('data', data => {
        const id = data.toString();
        const isReady = id.substring(id.length - 8);
        if (isReady.includes(marker) && close) {
            argsFile.write(terminate + '\n');
        }
    });
    fs.createReadStream(target).pipe(exiftool.stdin);
    argsFile.write(act + '\n');
    return exiftool.stdout;
}

(async () => {

    await pipeline(streamToExif('nikon_d850_01.nef', action), stripReadyEnd(), fs.createWriteStream('nikon_d850_01.json'));
    await pipeline(streamToExif('panasonic_s1r_01.rw2', action), stripReadyEnd(), fs.createWriteStream('panasonic_s1r_01.json'));
    await pipeline(streamToExif('canon_eos_1d_x_mark_iii_01.cr3', action), stripReadyEnd(), fs.createWriteStream('canon_eos_1d_x_mark_iii_01.json'));

    await timeout(1000);
    await pipeline(streamToExif('nikon_z7_ii_01.nef', action), stripReadyEnd(), fs.createWriteStream('nikon_z7_ii_01.json'));

    await timeout(1000);
    await pipeline(streamToExif('sony_a7r_iii_01.arw', action, true), stripReadyEnd(), fs.createWriteStream('sony_a7r_iii_01.json'));

})();

from extractd.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.