Move file-contents word to core/io/io.factor

db4
Aaron Schaefer 2007-12-30 21:29:27 -05:00
parent 8eff6af322
commit 41fa14010d
2 changed files with 20 additions and 21 deletions

View File

@ -1,8 +1,8 @@
! Copyright (C) 2003, 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: hashtables generic kernel math namespaces sequences strings
continuations assocs io.files io.styles sbufs ;
IN: io
USING: hashtables generic kernel math namespaces
sequences strings continuations assocs io.styles sbufs ;
GENERIC: stream-close ( stream -- )
GENERIC: set-timeout ( n stream -- )
@ -90,3 +90,6 @@ SYMBOL: stdio
: contents ( stream -- str )
2048 <sbuf> [ stream-copy ] keep >string ;
: file-contents ( path -- str )
dup <file-reader> swap file-length <sbuf> [ stream-copy ] keep >string ;

View File

@ -1,7 +1,7 @@
! Copyright (C) 2007 Adam Wendt.
! See http://factorcode.org/license.txt for BSD license.
!
USING: alien alien.c-types byte-arrays io io.binary io.files kernel mad namespaces prettyprint sbufs sequences tools.interpreter vars ;
USING: alien alien.c-types byte-arrays io io.binary io.files kernel mad
namespaces prettyprint sbufs sequences tools.interpreter vars ;
IN: mad.api
VARS: buffer-start buffer-length output-callback-var ;
@ -16,27 +16,27 @@ VARS: buffer-start buffer-length output-callback-var ;
{ "void*" "mad_header*" } create-mad-callback-generic ; inline
: create-filter-callback ( sequence -- alien )
{ "void*" "mad_stream*" "mad_frame*" } create-mad-callback-generic ; inline
{ "void*" "mad_stream*" "mad_frame*" } create-mad-callback-generic ; inline
: create-output-callback ( sequence -- alien )
{ "void*" "mad_header*" "mad_pcm*" } create-mad-callback-generic ; inline
{ "void*" "mad_header*" "mad_pcm*" } create-mad-callback-generic ; inline
: create-error-callback ( sequence -- alien )
{ "void*" "mad_stream*" "mad_frame*" } create-mad-callback-generic ; inline
{ "void*" "mad_stream*" "mad_frame*" } create-mad-callback-generic ; inline
: create-message-callback ( sequence -- alien )
{ "void*" "void*" "uint*" } create-mad-callback-generic ; inline
{ "void*" "void*" "uint*" } create-mad-callback-generic ; inline
: input ( buffer mad_stream -- mad_flow )
"input" print flush
nip ! mad_stream
nip ! mad_stream
buffer-start get ! mad_stream start
buffer-length get ! mad_stream start length
dup 0 = ! mad-stream start length bool
[ 3drop MAD_FLOW_STOP ] ! mad_flow
[ mad_stream_buffer !
0 buffer-length set !
MAD_FLOW_CONTINUE ] if ; ! mad_flow
[ mad_stream_buffer !
0 buffer-length set !
MAD_FLOW_CONTINUE ] if ; ! mad_flow
: input-callback ( -- callback )
[ input ] create-input-callback ;
@ -46,11 +46,11 @@ VARS: buffer-start buffer-length output-callback-var ;
: filter-callback ( -- callback )
[ "filter" print flush 3drop MAD_FLOW_CONTINUE ] create-filter-callback ;
: write-sample ( sample -- )
4 >le write ;
: output ( data header pcm -- mad_flow )
: write-sample ( sample -- )
4 >le write ;
: output ( data header pcm -- mad_flow )
"output" . flush
-rot 2drop output-callback-var> call
[ MAD_FLOW_CONTINUE ] [ MAD_FLOW_STOP ] if ;
@ -80,11 +80,8 @@ VARS: buffer-start buffer-length output-callback-var ;
: make-decoder ( -- decoder )
"mad_decoder" malloc-object ;
: file-contents ( path -- string )
dup <file-reader> swap file-length <sbuf> [ stream-copy ] keep >byte-array ;
: malloc-file-contents ( path -- alien )
file-contents malloc-byte-array ;
file-contents >byte-array malloc-byte-array ;
: mad-run ( -- int )
make-decoder [ mad-init ] keep MAD_DECODER_MODE_SYNC mad_decoder_run ;
@ -98,4 +95,3 @@ VARS: buffer-start buffer-length output-callback-var ;
: mad-test ( -- results )
[ output-stdout ] >output-callback-var
"/home/adam/download/mp3/Misc/wutbf.mp3" decode-mp3 ;