<commit_before>// Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:build/build.dart';
import 'package:glob/glob.dart';
import 'package:path/path.dart' as path;

import 'reader.dart';
import 'writer.dart';
import '../package_graph/package_graph.dart';

/// Basic [AssetReader] which uses a [PackageGraph] to look up where to read
/// files from disk.
class FileBasedAssetReader implements RunnerAssetReader {
  final PackageGraph packageGraph;
  final List<String> ignoredDirs;

  FileBasedAssetReader(this.packageGraph,
      {this.ignoredDirs: const ['build', 'packages', '.pub']});

  @override
  FutureOr<bool> canRead(AssetId id) => _fileFor(id, packageGraph).exists();

  @override
  Future<List<int>> readAsBytes(AssetId id) async =>
      (await _fileForOrThrow(id, packageGraph)).readAsBytes();

  @override
  Future<String> readAsString(AssetId id, {Encoding encoding: UTF8}) async =>
      (await _fileForOrThrow(id, packageGraph))
          .readAsString(encoding: encoding);<commit_msg>Ensures assets aren't read with a null encoding (#293)<commit_after>// Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:build/build.dart';
import 'package:glob/glob.dart';
import 'package:path/path.dart' as path;

import 'reader.dart';
import 'writer.dart';
import '../package_graph/package_graph.dart';

/// Basic [AssetReader] which uses a [PackageGraph] to look up where to read
/// files from disk.
class FileBasedAssetReader implements RunnerAssetReader {
  final PackageGraph packageGraph;
  final List<String> ignoredDirs;

  FileBasedAssetReader(this.packageGraph,
      {this.ignoredDirs: const ['build', 'packages', '.pub']});

  @override
  FutureOr<bool> canRead(AssetId id) => _fileFor(id, packageGraph).exists();

  @override
  Future<List<int>> readAsBytes(AssetId id) async =>
      (await _fileForOrThrow(id, packageGraph)).readAsBytes();

  @override
  Future<String> readAsString(AssetId id, {Encoding encoding}) async =>
      (await _fileForOrThrow(id, packageGraph))
          .readAsString(encoding: encoding ?? UTF8);
{'fraction_non_alphanumeric': 0.12237623762376237, 'fraction_numerical': 0.005148514851485149, 'mean_word_length': 4.793577981651376, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5617309', 'n_tokens_mistral': 778, 'n_tokens_neox': 756, 'n_words': 237}