-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf723ab
commit 87f2873
Showing
5 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# @qifi/generate | ||
|
||
<!-- Some beautiful tags --> | ||
<p align="left"> | ||
<a href="https://www.npmjs.com/package/@qifi/generate"> | ||
<img alt="npm" src="https://badgen.net/npm/v/@qifi/generate"> | ||
</a> | ||
<a href="#usage"> | ||
<img alt="docs" src="https://img.shields.io/badge/-docs%20%26%20demos-1e8a7a"> | ||
</a> | ||
<a href="https://github.com/sponsors/LittleSound"> | ||
<img alt="docs" src="https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86"> | ||
</a> | ||
</p> | ||
|
||
Stream Generated QR Codes for data transmission | ||
|
||
## Sponsors | ||
|
||
<p align="center"> | ||
<a href="https://github.com/sponsors/LittleSound"> | ||
<img src="https://cdn.jsdelivr.net/gh/littlesound/sponsors/sponsors.svg"/> | ||
</a> | ||
</p> | ||
|
||
<p align="center"> | ||
This project is made possible by all the sponsors supporting my work <br> | ||
You can join them at my sponsors profile: | ||
</p> | ||
<p align="center"><a href="https://github.com/sponsors/LittleSound"><img src="https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86&style=for-the-badge" /></a></p> | ||
|
||
## Usage | ||
|
||
```javascript | ||
import { | ||
createGeneraterANSI, | ||
createGeneraterUnicode, | ||
createGeneraterUnicodeCompact, | ||
createGeneraterSVG, | ||
createGeneraterQRCodeArray, | ||
} from '@qifi/generate' | ||
|
||
const generaterSvg = createGeneraterSVG(new Uint8Array(file.buffer)) | ||
|
||
const generaterANSI = createGeneraterANSI(new Uint8Array(file.buffer), { | ||
// Size of each data slice | ||
sliceSize: 250, | ||
// Error correction level | ||
ecc: 'L', | ||
// Border width | ||
border: 2, | ||
}) | ||
|
||
// display QR Code in terminal | ||
for (const blockQRCode of generaterANSI()) { | ||
console.log(blockQRCode) | ||
} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { defineBuildConfig } from 'unbuild' | ||
|
||
export default defineBuildConfig({ | ||
entries: [ | ||
'src/index.ts', | ||
], | ||
declaration: true, | ||
rollup: { | ||
emitCJS: false, | ||
dts: { | ||
compilerOptions: { | ||
paths: {}, | ||
}, | ||
}, | ||
}, | ||
externals: [ | ||
'pako', | ||
], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@qifi/cli", | ||
"type": "module", | ||
"version": "0.0.3", | ||
"description": "Stream Generated QR Codes for file transmission in your terminal", | ||
"author": "Rizumu Ayaka <[email protected]>", | ||
"license": "MIT", | ||
"homepage": "https://github.com/qifi-dev/qrs#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/qifi-dev/qrs.git", | ||
"directory": "packages/cli" | ||
}, | ||
"bug": "https://github.com/qifi-dev/qrs/issues", | ||
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.mts", | ||
"default": "./dist/index.mjs" | ||
} | ||
}, | ||
"main": "./dist/index.mjs", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.mts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"dev": "tsx ./src", | ||
"build": "unbuild", | ||
"stub": "unbuild --stub" | ||
}, | ||
"dependencies": { | ||
"@qifi/generate": "workspace:*", | ||
"mime": "^4.0.4", | ||
"tsx": "^4.19.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env tsx | ||
|
||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
import process from 'node:process' | ||
import { appendFileHeaderMetaToBuffer, createGeneraterANSI } from '@qifi/generate' | ||
import mime from 'mime' | ||
|
||
// Function to read file and generate QR codes | ||
async function generateQRCodes(filePath: string, sliceSize: number = 80, fps: number = 20) { | ||
const fullPath = path.resolve(filePath) | ||
|
||
console.log('fullPath:', fullPath) | ||
await new Promise(resolve => setTimeout(resolve, 1000)) | ||
if (!fs.existsSync(fullPath)) { | ||
console.error(`File not found: ${fullPath}`) | ||
process.exit(1) | ||
} | ||
|
||
const fileBuffer = fs.readFileSync(fullPath) | ||
const data = new Uint8Array(fileBuffer) | ||
const meta = { | ||
filename: path.basename(fullPath), | ||
contentType: mime.getType(fullPath) || 'application/octet-stream', | ||
} | ||
|
||
const merged = appendFileHeaderMetaToBuffer(data, meta) | ||
|
||
const generator = createGeneraterANSI(merged, { | ||
urlPrefix: 'https://qrss.netlify.app/#', | ||
sliceSize, | ||
border: 2, | ||
}) | ||
|
||
// Clear console function | ||
const clearConsole = () => process.stdout.write('\x1Bc') | ||
|
||
// Display QR codes | ||
for (const blockQRCode of generator.fountain()) { | ||
clearConsole() | ||
console.log(blockQRCode) | ||
console.log(`${meta.filename} (${meta.contentType})`, '|', 'size:', data.length, 'bytes') | ||
await new Promise(resolve => setTimeout(resolve, 1000 / fps)) // Display each QR code for 1 second | ||
} | ||
} | ||
|
||
// Parse command line arguments | ||
const args = process.argv.slice(2) | ||
if (args.length < 1) { | ||
console.error('Usage: qr-file-transfer <file-path> [slice-size]') | ||
process.exit(1) | ||
} | ||
|
||
const [filePath, sliceSizeStr, fpsStr] = args | ||
const sliceSize = sliceSizeStr ? Number.parseInt(sliceSizeStr, 10) : undefined | ||
const fps = fpsStr ? Number.parseInt(fpsStr, 10) : undefined | ||
|
||
if (!filePath) { | ||
console.error('File path is required') | ||
process.exit(1) | ||
} | ||
|
||
generateQRCodes(filePath, sliceSize, fps) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.