
Security News
Open VSX Begins Implementing Pre-Publish Security Checks After Repeated Supply Chain Incidents
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.
@wpdas/wave-header
Advanced tools
Using this module you can generate, read and rewrite a WAVE-file header. It's very useful for fix wav file headers as well.
I developed this module with a purpose to fix wav files generated by FFmpeg using stream. It's well-known that every wav files that was generated by FFmpeg in a stream has an issue with its header information, and the final file presents issue with the total time (00:00). This module will definitely fix this issue.
You can use this module for many others purposes, of course.
Generating a WAVE-file header buffer:
const fs = require('fs');
const waveHeader = require('wave-header');
const fileSize = 141971546;
// Options: (length, {channels: 1, sampleRate: 44100, bitDepth: 16})
const fileHeaderBuffer = waveHeader.generateHeader(fileSize, { bitDepth: 16 });
Reading a WAVE-file header from buffer chunk:
const { promises } = require('fs');
const waveHeader = require('wave-header');
const HEADER_OFFSET = 44;
promises
// Read only the head chunk from the audio file (better performance and reliability)
.readFile('my-wav-file.wav', { start: 0, end: HEADER_OFFSET })
.then(bufferChunk => {
const header = waveHeader.readHeader(bufferChunk);
console.log(header);
/**
{
riffHead: 'RIFF',
fileSize: 4294967295,
waveHead: 'WAVE',
fmtHead: 'fmt ',
formatLength: 16,
audioFormat: 1,
channels: 1,
sampleRate: 44100,
byteRate: 88200,
blockAlign: 2,
bitDepth: 16,
data: 'LIST',
dataLength: 130
}
*/
});
Rewriting the header of an issued audio file in real time using stream process. You can use this example when you're using FFmpeg to get wav streamed file and fix the header:
const { promises, createReadStream, createWriteStream } = require('fs');
const waveHeader = require('wave-header');
const audioFileWithHeaderIssueDir = 'my-wav-file-with-header-issue.wav';
let firstChunkRead = false;
function fixAudioHeader(fileSize) {
const newHeaderBuffer = waveHeader.generateHeader(fileSize, {
bitDepth: 16
});
// Final file with header fixed
const writeStream = createWriteStream('my-wav-file-with-fixed-header.wav');
createReadStream(audioFileWithHeaderIssueDir).on('data', buffer => {
// WARNING: Rewrites the header information in a chunk of buffer. Must be used the first chunk of buffer from a .wav file.
if (!firstChunkRead) {
writeStream.write(
waveHeader.rewriteHeaderInBufferChunk(newHeaderBuffer, buffer)
);
firstChunkRead = true;
} else {
writeStream.write(buffer);
}
});
}
promises.stat(audioFileWithHeaderIssueDir).then(stats => {
fixAudioHeader(stats.size);
});
If you want to use similar process above with AWS.S3, you may want to use stream.PassThrough to write the fixed buffer.
FAQs
Generates, Reads and Rewrites a WAVE-file header.
The npm package @wpdas/wave-header receives a total of 177 weekly downloads. As such, @wpdas/wave-header popularity was classified as not popular.
We found that @wpdas/wave-header demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.

Research
/Security News
Threat actors compromised four oorzc Open VSX extensions with more than 22,000 downloads, pushing malicious versions that install a staged loader, evade Russian-locale systems, pull C2 from Solana memos, and steal macOS credentials and wallets.

Security News
Lodash 4.17.23 marks a security reset, with maintainers rebuilding governance and infrastructure to support long-term, sustainable maintenance.