Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@poppinss/file-generator
Advanced tools
Generate fake in-memory files for varying sizes
Note: This package is ESM only
This package allows you generate fake in-memory files of varying sizes. The generated file can be used during testing to test the file uploads functionality of your Node server.
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
The npm package @poppinss/file-generator receives a total of 3,326 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.