close

prefer-blob-reading-methods

Unreleased

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/prefer-blob-reading-methods': 'error',
    },
  },
]);

Rule Details

Prefer the promise-based Blob#arrayBuffer() and Blob#text() methods over the corresponding callback-based FileReader methods.

Examples of incorrect code for this rule:

fileReader.readAsArrayBuffer(blob);
fileReader.readAsText(blob);

Examples of correct code for this rule:

const arrayBuffer = await blob.arrayBuffer();
const text = await blob.text();

Calls that pass an encoding to FileReader#readAsText() are allowed because Blob#text() always decodes as UTF-8. Other FileReader methods are also left unchanged:

fileReader.readAsText(blob, "ascii");
fileReader.readAsDataURL(blob);

Original Documentation