File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /*
2+ dir-list.js
3+
4+ Example shows how to iterate over contents of a directory using Algorithmia's DataAPI.
5+
6+ */
7+
8+ var algorithmia = require ( "../lib/algorithmia.js" ) ;
9+ var client = algorithmia . client ( process . env . ALGORITHMIA_API_KEY ) ;
10+
11+ console . log ( "Creating directory..." ) ;
12+ var testDir = client . dir ( "data://.my/node_client_test" ) ;
13+ testDir . create ( function ( err ) {
14+ if ( err ) {
15+ console . log ( "Error: " + JSON . stringify ( err ) ) ;
16+ } else {
17+ console . log ( "Create directory succeeded. Deleting directory..." ) ;
18+ }
19+
20+ console . log ( "Deleting directory..." ) ;
21+ testDir . delete ( function ( err ) {
22+ if ( err ) {
23+ return console . log ( "Error: " + JSON . stringify ( err ) ) ;
24+ }
25+ console . log ( "Delete directory succeeded." ) ;
26+ } ) ;
27+ } ) ;
28+
Original file line number Diff line number Diff line change @@ -69,14 +69,16 @@ AlgorithmiaClient = (function() {
6969 } ) ;
7070 res . on ( 'end' , function ( ) {
7171 var body , buff , ct ;
72- ct = res . headers [ 'content-type' ] || accept ;
73- if ( ct . startsWith ( 'application/json' ) ) {
74- buff = chunks . join ( '' ) ;
75- body = buff === '' ? { } : JSON . parse ( buff ) ;
76- } else if ( ct . startsWith ( 'text/plain' ) ) {
77- body = chunks . join ( '' ) ;
78- } else {
79- body = Buffer . concat ( chunks ) ;
72+ ct = res . headers [ 'content-type' ] ;
73+ if ( typeof ct === 'string' ) {
74+ if ( ct . startsWith ( 'application/json' ) ) {
75+ buff = chunks . join ( '' ) ;
76+ body = buff === '' ? { } : JSON . parse ( buff ) ;
77+ } else if ( ct . startsWith ( 'text/plain' ) ) {
78+ body = chunks . join ( '' ) ;
79+ } else {
80+ body = Buffer . concat ( chunks ) ;
81+ }
8082 }
8183 if ( callback ) {
8284 if ( res . statusCode < 200 || res . statusCode >= 300 ) {
Original file line number Diff line number Diff line change @@ -66,14 +66,15 @@ class AlgorithmiaClient
6666 chunks .push chunk
6767
6868 res .on ' end' , ->
69- ct = res .headers [' content-type' ] || accept
70- if ct .startsWith (' application/json' )
71- buff = chunks .join (' ' )
72- body = if buff == ' ' then {} else JSON .parse (buff)
73- else if ct .startsWith (' text/plain' )
74- body = chunks .join (' ' )
75- else
76- body = Buffer .concat (chunks)
69+ ct = res .headers [' content-type' ]
70+ if typeof ct == ' string'
71+ if ct .startsWith (' application/json' )
72+ buff = chunks .join (' ' )
73+ body = if buff == ' ' then {} else JSON .parse (buff)
74+ else if ct .startsWith (' text/plain' )
75+ body = chunks .join (' ' )
76+ else
77+ body = Buffer .concat (chunks)
7778
7879 if callback
7980 if res .statusCode < 200 || res .statusCode >= 300
You can’t perform that action at this time.
0 commit comments