qrloop
Envelop big blob of data into frames that can be displayed in series of QR Codes.
NB. this library is generic enough to not even be used with QR Codes but still take optimization decision in regard to how QR code works and from empirical tests.
Install
for Web or Electron
yarn add qrloop
for React Native
yarn add qrloop
yarn add buffer # required
API
There are 2 parts of the library, the "exporter" that want to export the data via QR codes and the "importer" that will scan these QR codes and accumulate the frames until it reaches the final result.
exporter
The exporter only have 1 function to use: dataToFrames
.
import { dataToFrames } from "qrloop/exporter";
const frames: string[] = dataToFrames("hello world");
const frames = dataToFrames(Buffer.from([ 0x00, 0x01, ... ]));
const frames = dataToFrames(data, 140, 2);
You can find an implementation example in examples/web-text-exporter
.
importer
There are a few functions you can use to be able to consume and accumulate the frames over time.
The main function is parseFramesReducer
that you feed with each QR Code data and will accumulate a state. Consider that state a black box and prefer using the utility functions to extract out information.
import {
parseFramesReducer,
areFramesComplete,
framesToData,
progressOfFrames
} from "qrloop/importer";
const onResult = finalResult => console.log({ finalResult });
let frames = null;
const onBarCodeScanned = (data: string) => {
try {
frames = parseFramesReducer(frames, data);
if (areFramesComplete(frames)) {
onResult(framesToData(frames).toString());
} else {
console.log("Progress:", progressOfFrames(frames));
}
} catch (e) {
console.warn(e);
}
};
You can find an implementation example in examples/rn-text-importer
.