// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.// Ported to Deno from// Copyright 2009 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.importtype{Reader}from"./types.d.ts"; /** OneByteReader returns a Reader that implements * each non-empty Read by reading one byte from r. */exportclassOneByteReaderimplementsReader{constructor(readonly r:Reader){} read(p:Uint8Array):Promise<number|null>{if(p.byteLength===0){returnPromise.resolve(0);}if(!(p instanceofUint8Array)){throwError("expected Uint8Array");}returnPromise.resolve(this.r.read(p.subarray(0,1)));}} /** HalfReader returns a Reader that implements Read * by reading half as many requested bytes from r. */exportclassHalfReaderimplementsReader{constructor(readonly r:Reader){} read(p:Uint8Array):Promise<number|null>{if(!(p instanceofUint8Array)){throwError("expected Uint8Array");}const half =Math.floor((p.byteLength+1)/2);returnPromise.resolve(this.r.read(p.subarray(0, half)));}} /** TimeoutReader returns `Deno.errors.TimedOut` on the second read * with no data. Subsequent calls to read succeed. */exportclassTimeoutReaderimplementsReader{ count =0;constructor(readonly r:Reader){} read(p:Uint8Array):Promise<number|null>{this.count++;if(this.count===2){thrownewDeno.errors.TimedOut();}returnPromise.resolve(this.r.read(p));}}