stepIndexer.js
function check_STEP_file(filename, callback) {

    "use strict";

    // "ISO-10303-21;"
    // "HEADER;"
    var stream = fs.createReadStream(filename, {flags:"r"});

    var fileData = "";
    stream.on('data', function (data) {
        fileData += data;

        // The next lines should be improved
        var lines = fileData.split("\n");

        if (lines.length >= 2) {

            stream.destroy();
            if (!pattern_ISO_10303_21.test(lines[0])) {
                my_callback(new Error("this file is not a STEP FILE : ISO_10303_21 missing"));
            } else {
                my_callback(null, lines[0]);
            }
        }
    });
    stream.on('error', function () {
        my_callback('Error', null);
    });

    stream.on('end', function () {
        my_callback('File end reached without finding line', null);
    });

    var callback_called = false;

    function my_callback(err, data) {
        if (!callback_called) {
            callback_called = true;
            callback(err, data);
        }
    }
}
function check_STEP_file(filename, callback) {

    "use strict";

    // "ISO-10303-21;"
    // "HEADER;"
    var stream = fs.createReadStream(filename, {flags:"r"});

    var fileData = "";
    stream.on('data', function (data) {
        fileData += data;

        // The next lines should be improved
        var lines = fileData.split("\n");

        if (lines.length >= 2) {

            stream.destroy();
            if (!pattern_ISO_10303_21.test(lines[0])) {
                my_callback(new Error("this file is not a STEP FILE : ISO_10303_21 missing"));
            } else {
                my_callback(null, lines[0]);
            }
        }
    });
    stream.on('error', function () {
        my_callback('Error', null);
    });

    stream.on('end', function () {
        my_callback('File end reached without finding line', null);
    });

    var callback_called = false;

    function my_callback(err, data) {
        if (!callback_called) {
            callback_called = true;
            callback(err, data);
        }
    }
}
function check_STEP_file ( filename , callback ) { "use strict" ; // "ISO-10303-21;" // "HEADER;" var stream = fs . createReadStream ( filename , { flags : "r" } ) ; var fileData = "" ; stream . on ( 'data' , function ( data ) { fileData += data ; // The next lines should be improved var lines = fileData . split ( "\n" ) ; if ( lines . length >= 2 ) { stream . destroy ( ) ; if ( ! pattern_ISO_10303_21 . test ( lines [ 0 ] ) ) { my_callback ( new Error ( "this file is not a STEP FILE : ISO_10303_21 missing" ) ) ; } else { my_callback ( null , lines [ 0 ] ) ; } } } ) ; stream . on ( 'error' , function ( ) { my_callback ( 'Error' , null ) ; } ) ; stream . on ( 'end' , function ( ) { my_callback ( 'File end reached without finding line' , null ) ; } ) ; var callback_called = false ; function my_callback ( err , data ) { if ( ! callback_called ) { callback_called = true ; callback ( err , data ) ; } } }
return true if the file is a correct STEP file
a correct STEP file starts with
ISO-10303-21;
HEADER;

@param filename
@param callback
return true if the file is a correct STEP file a correct STEP file starts with ISO - 10303 - 21 ; HEADER ;