
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
file-type-stream2
Advanced tools
"application/octet-stream"
. For detection it uses file-type module.Requires Node.js v5.10.0
$ npm install file-type-stream2
Explanation of 'how it works' step by step (examples in next section):
readableStream
.pipe( fileTypeStream( (fileType) => {
writableStream.fileType = fileType} ))
.pipe(writableStream);
fileType = {ext: "", mime: "application/octet-stream"
).import { fileTypeStream } from "file-type-stream2";
// const { fileTypeStream } from "file-type-stream2";
readStream
.pipe( fileTypeStream( function(fileType) {
writeStream.mime = fileType.mime;
writeStream.ext = fileType.ext;
}))
.pipe(writeStream); // writeStream will NOT receive any data before file type recognized.
import { fileTypeStream } from "file-type-stream2";
let fts = fileTypeStream();
fts.onFileType( function(fileType) { // Equivalent of fts.on("fileType", function(fileType){...})
writeStream.mime = fileType.mime;
writeStream.ext = fileType.ext;
});
readStream
.pipe( fts )
.pipe( writeStream ); // writeStream will NOT receive any data before file type recognized.
import { fileTypeStream } from "file-type-stream2";
let fts = fileTypeStream( function(fileType) {
writeStream.mime = fileType.mime; // *This will be SECOND
writeStream.ext = fileType.ext;
});
fts.onFileType( function(fileType) {
writeStream.mime = fileType.mime; // *This will be FIRST
writeStream.ext = fileType.ext;
});
readStream
.pipe( fts )
.pipe( writeStream ); // writeStream will NOT receive any data before file type recognized.
If you want only detect file type basing on it's content then this example is for you. You just have to use file-type module:
import fileType from "file-type";
// let fileType = require("file-type");
let first_4100_bytes_buffer = getFirstBytesSomehow(); // you can be less efficient and read whole file into buffer
let ft = fileType(first_4100_bytes_buffer);
ft = ft && ft.mime; // mime type string or null
fileTypeStream
function that returns Duplex stream file type detector.FileTypeStream2
class (for typing purposes only).DuplexOptions
interface.FileTypeResult
interface.fileTypeStream( callback?: (fileTypeResult: FileTypeResult) => void, opts?: DuplexOptions ): FileTypeStream2
This function is exported directly from module.
It returns FileTypeStream2 instance that is native Duplex stream (details below).
[callback] (fileTypeResult: {mime: string, ext: string}) => void
:callback
will be called with proper FileTypeResult
object ({mime: string, ext: string}
).FileTypeStream2::onFileType
also can be used to provide additonal callback
- in this case both callbacks would be called in preceding order: onFileType callback and then fileTypeStream callback.[opts] DuplexOptions
:Duplex
stream).objectMode
because file type detection will not be possible (expect unhandled error).hihgWaterMark
).FileTypeStream2
extends Duplex
streamInternal class returned by fileTypeStream
function. Documented only for development purposes.
constructor( callback?: (fileTypeResult: FileTypeResult) => void, opts?: DupexOptions )
fileTypeStream
function for you.
[callback] (fileTypeResult: FileTypeResult) => void
:callback
will be called with proper fileTypeResult
object ({mime: string, ext: string}
) (onFileType
method also can be used to provide additonal callback
).[opts] DuplexOptions
:Duplex
stream. Do NOT set to objectMode
because file type detection will not be possible (expect unhandled error).Use only if you are aware of what you are doing (eg. set custom hihgWaterMark
).onFileType( callback: (fileTypeResult: FileTypeResult) => void )
callback
will be called with proper fileTypeResult
string. This method is equivalent of on("fileType", callback)
.
[callback] (fileTypeResult: FileTypeResult) => void
:callback
will be called with proper fileTypeResult
object ({mime: string, ext: string}
) (The same callback can be provided also via constructor
).FileTypeResult
Interface returned from file-type module.
Argument provided for your callbacks.
ext: string
""
value).mime: string
:"application/octet-stream"
value).FAQs
Improved detection of file type basing on it's binary content.
We found that file-type-stream2 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.