Ejemplo n.º 1
0
 protected void ThrowError(string domErrorName) {
   this.error = new DOMError(domErrorName);
   this.result = null;
   this.readyState = DONE;
   OnOnLoadEnd(new ProgressEventArgs(false, 0, 0));
 }
Ejemplo n.º 2
0
    public async void ReadAsText(Blob blob, string tryEncoding) {
      if (this.readyState == LOADING) {
        ThrowError(DOM_ERROR_INVALID_STATE);
        return;
      }

      this.readyState = LOADING;
      Encoding encoding = LookupEncoding(tryEncoding);

      using (Stream stream = TryOpenStream(blob)) {
        if (stream == null) return; // We called ThrowError() already

        using (StreamReader reader = new StreamReader(stream, encoding)) {
          // StreamReader's ctor won't throw an exception

          this.result = await TryReadToEndAsync(reader);
          if (this.result == null) return; // We called ThrowError() already

          this.error = null;
          this.readyState = DONE;
          OnOnLoadEnd(new ProgressEventArgs(true, (ulong) result.Length, (ulong) result.Length));
        }
      }
    }