Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@poppinss/file-generator
Advanced tools
Generate fake in-memory files for varying sizes
This package allows you generate fake in-memory files for varying sizes. The generated file can be used during testing to test the file uploads functionality of your Node server.
docx
, 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 { generatePng } from '@poppinss/file-generator'
const {
contents,
size,
mime,
name
} = await 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 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 generatePng('1mb')
form.append('avatar', file.contents, {
filename: file.name,
contentType: file.mime,
knownLength: file.size,
})
FAQs
Generate in-memory fake files for custom size
The npm package @poppinss/file-generator receives a total of 15,745 weekly downloads. As such, @poppinss/file-generator popularity was classified as popular.
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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.