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AAY,cAAgB,EAAY,gBAAkB,KAE/H,CA/DA,GAAG,KAAK,EAAI,EAAQ,EAAG,GAAI,GAAG,SAAS,EAAK,GAE1C,IAAI,EAAE,EACF,EAAU,GACd,SAAS,IACP,IAAI,EAAO,EAAM,GAiBjB,OAfA,IACY,UAAT,EAAK,IACN,EAAY,EAAK,IAAM,EAAO,SAAS,QAAS,EAAU,EAAU,EAAK,IACzE,GAAoB,EAAK,IAEV,WAAT,EAAK,IAEX,EAAY,EAAK,IAAM,EAAO,aAAa,EAAS,EAAK,IACzD,GAAoB,EAAK,IAEV,YAAT,EAAK,KAEX,EAAY,EAAK,IAAM,EAAO,YAAY,EAAS,EAAK,IACxD,GAAoB,EAAK,IAExB,EAAI,EAAM,OAAiB,IAChB,GAAG,MAAM,EAAI,EAE7B,CAEA,EACF,GAoCF,GACF,GACA,OAAO,QAAU","file":"/npm/wav-file-info@0.0.10/wav-file-info.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/wav-file-info@0.0.10/wav-file-info.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// Hi Welcome to WFI by David Jones / RackFX, LLC\nvar fs = require('fs');\nvar wfi = {}\n\nwfi.infoByFilename = function(filename, cb){\n  var stats = fs.statSync(filename)\n  var buffer = new Buffer(40);  // first 40 bytes are RIFF header\n  fs.open(filename, 'r', function(err, fd) {\n    if(err) return cb(err);  // error probably TODO:check this!\n\n    // ex error -\n    // { [Error: ENOENT: no such file or directory, open './test.wav'] errno: -2, code: 'ENOENT', syscall: 'open', path: './test.wav' }\n    var read_result = {}\n\n\n    // this a list of sequenced bytes in the 40 byte header. This builds the read_result object.\n    //  Property name / Data type / Length\n    var reads = [\n      ['riff_head', 'string', 4],\n      ['chunk_size','uinteger', 4],\n      ['wave_identifier', 'string', 4],\n      ['fmt_identifier', 'string', 4],\n      ['subchunk_size','integer',4],\n      ['audio_format','integer',2],\n      ['num_channels','integer',2],\n      ['sample_rate','uinteger',4],\n      ['byte_rate','integer',4],\n      ['block_align','integer',2],\n      ['bits_per_sample','integer',2],\n      //['uhm','integer',2],\n      ['data_identifier','string', 4],\n      //['sub_chunk2_size', 'integer', 4],\n\n    ]\n    fs.read(fd, buffer, 0, 40, 0, function(err, num) {\n\n      var i=0;\n      var pointer = 0;\n      function read_wav(){\n        var read = reads[i];\n\n        i++;\n        if(read[1]=='string'){\n          read_result[read[0]] = buffer.toString('ascii', pointer , pointer + read[2]);\n          pointer = pointer + read[2];   // pointer = pointer plus # bytes\n        }\n        else if(read[1]=='integer'){\n\n          read_result[read[0]] = buffer.readUInt16LE(pointer, read[2])\n          pointer = pointer + read[2];\n        }\n        else if(read[1]=='uinteger'){\n\n          read_result[read[0]] = buffer.readInt32LE(pointer, read[2])\n          pointer = pointer + read[2];\n        }\n        if(i < reads.length) { return read_wav()}\n        else { return fs.close(fd, post_process); }\n\n      }\n      //console.log(i)\n      read_wav();\n    }); // end fs.read\n\n    function post_process(){\n      var error = false;\n      var invalid_reasons = []\n\n      if (read_result.riff_head != \"RIFF\")  invalid_reasons.push(\"Expected \\\"RIFF\\\" string at 0\" )\n      if (read_result.wave_identifier != \"WAVE\") invalid_reasons.push(\"Expected \\\"WAVE\\\" string at 4\")\n      if (read_result.fmt_identifier != \"fmt \") invalid_reasons.push(\"Expected \\\"fmt \\\" string at 8\")\n      if (\n        (read_result.audio_format != 1) &&        // Wav PCM\n        (read_result.audio_format != 65534)  &&   // Extensible PCM\n        (read_result.audio_format != 2)  &&       // Wav\n        (read_result.audio_format != 6) &&        // Wav ALAW\n        (read_result.audio_format != 7) &&        // Wav MULAW\n        (read_result.audio_format != 22127)  &&   // Vorbis ?? (issue #11)\n        (read_result.audio_format != 3))          // Wav\n              invalid_reasons.push(\"Unknown format: \"+read_result.audio_format)\n      if ((read_result.chunk_size + 8) !== stats.size) invalid_reasons.push(\"chunk_size does not match file size\")\n      //if ((read_result.data_identifier) != \"data\") invalid_reasons.push(\"Expected data identifier at the end of the header\")\n\n      if (invalid_reasons.length > 0) error = true;\n\n      if (error) return cb({\n        error : true,\n        invalid_reasons: invalid_reasons,\n        header: read_result,\n        stats: stats\n      });\n\n      cb(null, {\n        header: read_result,\n        stats: stats,\n        duration: ((read_result.chunk_size) / (read_result.sample_rate * read_result.num_channels * (read_result.bits_per_sample / 8)))\n      });\n    }\n  });\n}\nmodule.exports = wfi;\n"]}