Language: TypeScript
Label: safe
CWE: CWE-331 \u2014 Insufficient Entropy
The product uses an algorithm or scheme that produces insufficient entropy, leaving patterns or clusters of values that are more likely to occur than others.

Code:
  constructor({ stream, data, encoding, name, mimeType }) {
    if (stream instanceof Readable) {
      this.data = stream;

      if (stream instanceof fs.ReadStream) {
        // $FlowFixMe: incomplete flow node definitions
        this.name = basename(stream.path);
        this.contentLength = fs.statSync(stream.path).size;
      }
    } else if (data instanceof Buffer) {
      this.data = Buffer.from(data);
    } else if (typeof data === 'string') {
      // $FlowFixMe: incomplete flow node definitions
      this.data = Buffer.from(data, encoding ?? 'utf8');
    }

    if (name) {
      this.name = basename(name);
    }

    if (mimeType) {
      this.mimeType = mimeType;
    }

    if (this.data === undefined) {
      throw new Error("Couldn't construct a file out of supplied options.");
    }

    if (this.name === undefined) {
      throw new Error("Couldn't guess filename out of the options. Please provide one.");
    }
  }