@@ -10,20 +10,6 @@ const mh = require('multihashes')
1010const Unixfs = require ( 'ipfs-unixfs' )
1111const assert = require ( 'assert' )
1212
13- function normalizeMultihash ( multihash , enc ) {
14- if ( typeof multihash === 'string' ) {
15- if ( enc === 'base58' || ! enc ) {
16- return multihash
17- }
18-
19- return new Buffer ( multihash , enc )
20- } else if ( Buffer . isBuffer ( multihash ) ) {
21- return multihash
22- } else {
23- throw new Error ( 'unsupported multihash' )
24- }
25- }
26-
2713function parseBuffer ( buf , encoding , callback ) {
2814 switch ( encoding ) {
2915 case 'json' :
@@ -178,20 +164,19 @@ module.exports = function object (self) {
178164 }
179165 } ) ,
180166
181- get : promisify ( ( multihash , options , callback ) => {
167+ get : promisify ( ( hash , options , callback ) => {
182168 if ( typeof options === 'function' ) {
183169 callback = options
184170 options = { }
185171 }
186172
187- let mh
173+ let cid
188174
189175 try {
190- mh = normalizeMultihash ( multihash , options . enc )
176+ cid = new CID ( hash )
191177 } catch ( err ) {
192178 return callback ( err )
193179 }
194- const cid = new CID ( mh )
195180
196181 self . _ipldResolver . get ( cid , ( err , result ) => {
197182 if ( err ) {
@@ -204,13 +189,21 @@ module.exports = function object (self) {
204189 } )
205190 } ) ,
206191
207- data : promisify ( ( multihash , options , callback ) => {
192+ data : promisify ( ( hash , options , callback ) => {
208193 if ( typeof options === 'function' ) {
209194 callback = options
210195 options = { }
211196 }
212197
213- self . object . get ( multihash , options , ( err , node ) => {
198+ let cid
199+
200+ try {
201+ cid = new CID ( hash )
202+ } catch ( err ) {
203+ return callback ( err )
204+ }
205+
206+ self . object . get ( cid , options , ( err , node ) => {
214207 if ( err ) {
215208 return callback ( err )
216209 }
0 commit comments