this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

trying to remove leaks

+149 -59
+61 -59
src/formats/flac.odin
··· 32 32 delete(c.title, allocator) 33 33 delete(c.album, allocator) 34 34 delete(c.album_artist, allocator) 35 - for artist in c.artists { 36 - delete(artist, allocator) 37 - } 38 - delete(c.artists, allocator) 35 + delete(c.artists) 39 36 } 40 37 41 38 check_is_flac :: proc(r: ^bufio.Reader) -> bool { ··· 133 130 } 134 131 cursor += 4 135 132 133 + artists: [dynamic]string 134 + 136 135 // Read fields 137 136 comment: VorbisComment 138 137 for i in 0 ..< num_fields { ··· 168 167 169 168 fmt.printfln("key |%v| value |%v| ", key, value) 170 169 170 + 171 171 switch key { 172 172 case "ALBUM": 173 - comment.album = value 173 + comment.album = strings.clone(value) 174 174 case "ARTIST": 175 - append(&comment.artists, value) 175 + append(&artists, strings.clone(value)) 176 176 case "ALBUM ARTIST": 177 - comment.album_artist = value 177 + comment.album_artist = strings.clone(value) 178 178 case "TITLE": 179 - comment.title = value 179 + comment.title = strings.clone(value) 180 180 case "TRACK NUMBER": 181 181 track_number, ok := strconv.parse_int(value) 182 182 if !ok { ··· 187 187 cursor += field_length 188 188 } 189 189 190 + comment.artists = artists[:] 191 + 190 192 if comment.album_artist == "" && len(comment.artists) > 0 { 191 193 comment.album_artist = comment.artists[0] 192 194 } ··· 195 197 } 196 198 197 199 198 - read :: proc(file: ^os.File) -> (c: VorbisComment, err: ReadError) { 200 + flac_read :: proc(file: ^os.File) -> (c: VorbisComment, err: ReadError) { 199 201 200 202 r: bufio.Reader 201 - buffer: [1024 * 8]byte 203 + buffer: [1024]byte 202 204 stream := os.to_reader(file) 203 205 bufio.reader_init_with_buf(&r, stream, buffer[:]) 204 206 defer bufio.reader_destroy(&r) ··· 283 285 defer os.close(f) 284 286 285 287 286 - actual, err := read(f) 288 + actual, err := flac_read(f) 289 + defer destroy_vorbis_comment(actual) 287 290 288 291 fmt.printfln("Actual: %v", actual) 289 292 ··· 299 302 ) 300 303 } 301 304 305 + @(test) 306 + should_check_flac_file :: proc(t: ^testing.T) { 302 307 303 - //@(test) 304 - //should_check_flac_file :: proc(t: ^testing.T) { 305 - // 306 - // file_path := "../../test-data/07. Vampire in the Corner.flac" 307 - // f, ferr := os.open(file_path, {.Read}) 308 - // if ferr != nil { 309 - // fmt.eprintfln("{}", ferr) 310 - // testing.expect(t, false, "failed to open flac file") 311 - // } 312 - // defer os.close(f) 313 - // 314 - // 315 - // r: bufio.Reader 316 - // buffer: [1024]byte 317 - // bufio.reader_init_with_buf(&r, os.to_reader(f), buffer[:]) 318 - // defer bufio.reader_destroy(&r) 319 - // 320 - // actual := check_is_flac(&r) 321 - // 322 - // testing.expect(t, actual == true, "failed to open flac file") 323 - //} 324 - // 325 - // 326 - //@(test) 327 - //should_return_error_on_non_flac_file :: proc(t: ^testing.T) { 328 - // 329 - // file_path := "../../test-data/08. Last Dinosaurs - Purxst.wav" 330 - // f, ferr := os.open(file_path, {.Read}) 331 - // if ferr != nil { 332 - // fmt.eprintfln("{}", ferr) 333 - // testing.expect(t, false, "failed to open flac file") 334 - // } 335 - // defer os.close(f) 336 - // 337 - // 338 - // r: bufio.Reader 339 - // buffer: [1024]byte 340 - // bufio.reader_init_with_buf(&r, os.to_reader(f), buffer[:]) 341 - // defer bufio.reader_destroy(&r) 342 - // 343 - // actual := check_is_flac(&r) 344 - // 345 - // testing.expect( 346 - // t, 347 - // actual == false, 348 - // "check_is_flac was supposed to return false for non flac file", 349 - // ) 350 - //} 308 + file_path := "../../test-data/07. Vampire in the Corner.flac" 309 + f, ferr := os.open(file_path, {.Read}) 310 + if ferr != nil { 311 + fmt.eprintfln("{}", ferr) 312 + testing.expect(t, false, "failed to open flac file") 313 + } 314 + defer os.close(f) 315 + 316 + 317 + r: bufio.Reader 318 + buffer: [1024]byte 319 + bufio.reader_init_with_buf(&r, os.to_reader(f), buffer[:]) 320 + defer bufio.reader_destroy(&r) 321 + 322 + actual := check_is_flac(&r) 323 + 324 + testing.expect(t, actual == true, "failed to open flac file") 325 + } 326 + 327 + 328 + @(test) 329 + should_return_error_on_non_flac_file :: proc(t: ^testing.T) { 330 + 331 + file_path := "../../test-data/08. Last Dinosaurs - Purxst.wav" 332 + f, ferr := os.open(file_path, {.Read}) 333 + if ferr != nil { 334 + fmt.eprintfln("{}", ferr) 335 + testing.expect(t, false, "failed to open flac file") 336 + } 337 + defer os.close(f) 338 + 339 + 340 + r: bufio.Reader 341 + buffer: [1024]byte 342 + bufio.reader_init_with_buf(&r, os.to_reader(f), buffer[:]) 343 + defer bufio.reader_destroy(&r) 344 + 345 + actual := check_is_flac(&r) 346 + 347 + testing.expect( 348 + t, 349 + actual == false, 350 + "check_is_flac was supposed to return false for non flac file", 351 + ) 352 + }
+88
src/library/library.odin
··· 1 + package library 2 + 3 + import formats "../formats" 4 + import "core:fmt" 5 + import "core:mem" 6 + import os "core:os/os2" 7 + import "core:slice" 8 + import "core:strings" 9 + import "core:testing" 10 + 11 + 12 + is_flac :: proc(fi: os.File_Info) -> bool { 13 + return strings.ends_with(fi.name, ".flac") 14 + } 15 + 16 + read_dir :: proc( 17 + path: string, 18 + allocator: mem.Allocator = context.allocator, 19 + ) -> ( 20 + result: []formats.VorbisComment, 21 + ok: bool, 22 + ) { 23 + real_path, err := os.get_absolute_path(path, allocator) 24 + defer delete(real_path) 25 + 26 + 27 + if err != nil { 28 + return nil, false 29 + } 30 + 31 + dir_entries: []os.File_Info 32 + dir_entries, err = os.read_all_directory_by_path(real_path, allocator) 33 + defer delete(dir_entries) 34 + 35 + fmt.printfln("Dir entries: %v", dir_entries) 36 + 37 + if err != nil { 38 + return nil, false 39 + } 40 + 41 + dir_slice := dir_entries[:] 42 + only_flac := slice.filter(dir_slice, is_flac) 43 + defer delete(only_flac) 44 + 45 + fmt.printfln("only flac: %v", only_flac) 46 + 47 + length := len(only_flac) 48 + 49 + res := make([]formats.VorbisComment, length) 50 + defer delete(res) 51 + 52 + file: ^os.File 53 + ferr: os.Error 54 + 55 + for i in 0 ..< length { 56 + entry := only_flac[i] 57 + 58 + fmt.printfln("entry %v", entry) 59 + file, ferr = os.open(entry.fullpath, {.Read}) 60 + defer os.close(file) 61 + if ferr != nil { 62 + return nil, false 63 + } 64 + comment, err := formats.flac_read(file) 65 + if err != nil { 66 + return nil, false 67 + } 68 + res[i] = comment 69 + os.close(file) 70 + } 71 + 72 + return res, true 73 + } 74 + 75 + @(test) 76 + should_read_dir :: proc(t: ^testing.T) { 77 + dir_path := "../../test-data" 78 + 79 + result, ok := read_dir(dir_path) 80 + 81 + fmt.printfln("Results: %v", result) 82 + 83 + testing.expect(t, ok) 84 + 85 + for x in result { 86 + formats.destroy_vorbis_comment(x) 87 + } 88 + }