D
D
Danil2016-07-18 12:53:14
Node.js
Danil, 2016-07-18 12:53:14

How to work with buffer in nodejs?

I have this code that makes me a barcode and saves it to a directory. But after execution the script "hangs". How to terminate it after saving the file?

function createImage() {
        bwipjs.toBuffer({
            bcid:        'code128',       // Barcode type 
            text:        '0123456789',    // Text to encode 
            scale:       3,               // 3x scaling factor 
            height:      10,              // Bar height, in millimeters 
            includetext: true,            // Show human-readable text 
            textxalign:  'center',        // Always good to set this 
            //textfont:    'Inconsolata',   // Use your custom font 
            textsize:    13               // Font size, in points 
        }, function (err, png) {
            if (err) {
                console.log(err)
                // Decide how to handle the error 
                // `err` may be a string or Error object 
            } else {

                fs.writeFile('images/test.png', png, function(err) {

                });
                // `png` is a Buffer 
                // png.length           : PNG file length 
                // png.readUInt32BE(16) : PNG image width 
                // png.readUInt32BE(20) : PNG image height 
            }
        });
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yociyavi, 2016-07-18
@Veneomin

process.exit()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question