pullXX method

Future<Uint8List> pullXX(
  1. String xxInt,
  2. String shortLink,
  3. String pullFromUrl
)

Implementation

Future<Uint8List> pullXX(
    String xxInt, String shortLink, String pullFromUrl) async {
  //List<int> xx = attachment.sublist(attachment.length - 8, attachment.length);
  //String xxi = HEX.encode(xx);
  if (_xxStash[xxInt] != null) return _xxStash[xxInt]!;
  if (_xxCid[xxInt] != null) {
    final u = await _io?.readCid(_xxCid[xxInt]!);
    if (u != null && u.isNotEmpty) {
      _xxStash[xxInt] = u;
      return u;
    }
  }

  //if (!molo.ghostMode) {
  //final value = _io?.readXX(xxInt.toString());
  //if (value != null) return value;
  return Uint8List(0);
/*
  if (!_diskFetch.contains(xxInt)) {
    _diskFetch.add(xxInt);
    try {
      var value = _io?.readXX(xxInt).then((value) {
        if (value != null) {
          if (value.isNotEmpty) {
            _xxWants.remove(xxInt);
            _diskFetch.remove(xxInt);
            _diskMissing.remove(xxInt);
            _xxStash[xxInt] = value.buffer.asUint8List();
            return _xxStash[xxInt]!;
          }
        }
      });

      _diskMissing.add(xxInt);
      return Uint8List(0);
      //});
    } catch (e) {
      //return null;
      _pulling = 0;
    }
    return Uint8List(0); //dont do disk check twice
  }

  if (_xxWants.contains(xxInt)) {
    //dont allow multi reqs for the same item
    return Uint8List(0);
  }

  _xxWants.add(xxInt);

  /*if (_pulling == 0) {
    _pulling = now;
  } else {
    if (now - _pulling < 500) {
      return Uint8List(0);
    }
    _pulling = now;
  }*/
  bool pl = false;
  if (shortLink.isEmpty) return Uint8List(0);
  Random rnd = new Random();
  var r = 50 + rnd.nextInt(500 - 100);

  HttpClient()
      .getUrl(Uri.parse(
          pullFromUrl + '/xx/' + shortLink)) // produces a request object
      .then((request) => request.close()) // sends the request
      .then((response) async {
    //print(response.toString());
    //var rp = await response.toList();
    //print(utf8.decode(rp[0]));
    if (response.statusCode == 200) {
      final rp = await response.toList();
      if (rp.isEmpty) {
        _pulling = 0;
        return;
      }
      Uint8List r = Uint8List(1000000);
      int ff = 0;
      for (var i in rp) {
        for (var ii in i) {
          r[ff++] = ii;
        }
        _xxStash[xxInt] = r.sublist(0, ff);
        _io?.commitXX(r.sublist(0, ff), xxInt);
        _xxWants.remove(xxInt);
        if (_pulling > 0) {
          _pulling = 0;
        }
      }
    } else {
      if (_pulling > 0) {
        _pulling = 0;
      }
    }
  });

  return Uint8List(0);
*/
  //response.transform(Utf8Decoder()).listen(print)); //
}