
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@poppinss/file-generator
Advanced tools
Generate fake in-memory files for varying sizes
This package allows you generate fake in-memory files of varying sizes. The generated file buffer can be used to test file uploads.
docx
, csv
, xlsx
, pdf
, png
, jpg
, and gif
files.Install the package from the npm registry as follows.
npm i @poppinss/file-generator
# Yarn
yarn add @poppinss/file-generator
Use the exported functions as follows.
import fileGenerator from '@poppinss/file-generator'
const {
contents,
size,
mime,
name
} = await fileGenerator.generatePng('1mb')
contents
is a buffer.size
is the size of the file in bytes.mime
is the mime type for the generated file.name
is a randomly assigned unique name to the file.You can also define a custom file name as the second argument.
await fileGenerator.generatePng('1mb', 'avatar.png')
You can pass the generated content to an instance of form data as follows.
import FormData from 'form-data'
const form = new FormData()
const file = await fileGenerator.generatePng('1mb')
form.append('avatar', file.contents, {
filename: file.name,
contentType: file.mime,
knownLength: file.size,
})
Following are the available methods to generate different files.
generateDocx
- Generate a Microsoft word doc file (passes file-type validation).generateGif
- Generate a gif file (passes file-type validation).generateJpg
- Generate a jpeg file (passes file-type validation).generatePdf
- Generate a pdf file (passes file-type validation).generatePng
- Generate a png file (passes file-type validation).generateXlsx
- Generate a Microsoft excel spreadsheet (passes file-type validation).generateCsv
- Generate a CSV file.FAQs
Generate in-memory fake files for custom size
We found that @poppinss/file-generator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.