diff --git a/collects/meta/props b/collects/meta/props index a572485568..3f4592ac39 100755 --- a/collects/meta/props +++ b/collects/meta/props @@ -1800,6 +1800,7 @@ path/s is either such a string or a list of them. "collects/tests/units/test-runtime.rktl" drdr:command-line (racket "-f" *) "collects/tests/units/test-unit-contracts.rktl" drdr:command-line (racket "-f" *) "collects/tests/units/test-unit.rktl" drdr:command-line (racket "-f" *) +"collects/tests/unstable/byte-counting-port.rkt" responsible (jay) "collects/tests/unstable/generics.rkt" responsible (jay) "collects/tests/unstable/srcloc.rktl" responsible (cce) drdr:command-line (racket "-f" *) "collects/tests/utils" responsible (unknown) @@ -1839,6 +1840,7 @@ path/s is either such a string or a list of them. "collects/typed/rackunit/gui.rkt" drdr:command-line (gracket "-t" *) "collects/typed-scheme" responsible (samth) "collects/unstable" responsible (jay samth cce ryanc) +"collects/unstable/byte-counting-port.rkt" responsible (jay) "collects/unstable/debug.rkt" responsible (samth) "collects/unstable/gui/notify.rkt" drdr:command-line (gracket-text "-t" *) "collects/unstable/gui/prefs.rkt" drdr:command-line (gracket-text "-t" *) @@ -1846,6 +1848,7 @@ path/s is either such a string or a list of them. "collects/unstable/match.rkt" responsible (samth) "collects/unstable/mutated-vars.rkt" responsible (samth) "collects/unstable/poly-c.rkt" responsible (samth) +"collects/unstable/scribblings/byte-counting-port.scrbl" responsible (jay) "collects/unstable/scribblings/debug.scrbl" responsible (samth) "collects/unstable/scribblings/hash.scrbl" responsible (samth) "collects/unstable/scribblings/match.scrbl" responsible (samth) diff --git a/collects/tests/unstable/byte-counting-port.rkt b/collects/tests/unstable/byte-counting-port.rkt new file mode 100644 index 0000000000..bf98c31873 --- /dev/null +++ b/collects/tests/unstable/byte-counting-port.rkt @@ -0,0 +1,15 @@ +#lang racket +(require unstable/byte-counting-port + tests/eli-tester) + +(define name (gensym)) +(define cp (make-byte-counting-port name)) +(test + (object-name cp) => name + (for/fold ([l 0]) + ([i (in-range 100)]) + (define n (random 25)) + (test + (file-position cp) => l + (write-bytes (make-bytes n) cp)) + (+ l n))) \ No newline at end of file diff --git a/collects/unstable/byte-counting-port.rkt b/collects/unstable/byte-counting-port.rkt new file mode 100644 index 0000000000..d0de94c8da --- /dev/null +++ b/collects/unstable/byte-counting-port.rkt @@ -0,0 +1,17 @@ +#lang racket + +(define (make-byte-counting-port [name 'byte-counting-port]) + (define location 0) + (define (write-out bs starting ending opt1 opt2) + (define how-many-written (- ending starting)) + (set! location (+ location how-many-written)) + how-many-written) + (define close void) + (define (get-location) + (values #f #f location)) + (make-output-port name always-evt write-out close + #f #f #f + get-location)) + +(provide/contract + [make-byte-counting-port (any/c . -> . output-port?)]) \ No newline at end of file diff --git a/collects/unstable/scribblings/byte-counting-port.scrbl b/collects/unstable/scribblings/byte-counting-port.scrbl new file mode 100644 index 0000000000..17047a6ae0 --- /dev/null +++ b/collects/unstable/scribblings/byte-counting-port.scrbl @@ -0,0 +1,15 @@ +#lang scribble/manual +@(require "utils.rkt" (for-label racket unstable/byte-counting-port)) + +@title{Byte Counting Ports} + +@defmodule[unstable/byte-counting-port] + +@unstable[@author+email["Jay McCarthy" "jay@racket-lang.org"]] + +This library provides an output port constructor like @racket[open-output-nowhere], except it counts how many bytes have been written (available through @racket[file-position].) + +@defproc[(make-byte-counting-port [name any/c 'byte-counting-port]) + output-port?]{ +Creates and returns an output port that discards all output sent to it (without blocking.) The @racket[name] argument is used as the port's name. The total number bytes written is available through @racket[file-position].} + \ No newline at end of file diff --git a/collects/unstable/scribblings/unstable.scrbl b/collects/unstable/scribblings/unstable.scrbl index 19b157a98e..3fb0d3f56b 100644 --- a/collects/unstable/scribblings/unstable.scrbl +++ b/collects/unstable/scribblings/unstable.scrbl @@ -95,6 +95,7 @@ Keep documentation and tests up to date. @include-section["generics.scrbl"] @include-section["markparam.scrbl"] @include-section["debug.scrbl"] +@include-section["byte-counting-port.scrbl"] @;{--------}