✨ Implement Blocks function
This commit is contained in:
		
					parent
					
						
							
								ac16a3f167
							
						
					
				
			
			
				commit
				
					
						a495a2ef1a
					
				
			
		
					 2 changed files with 27 additions and 2 deletions
				
			
		
							
								
								
									
										27
									
								
								blocks.go
									
										
									
									
									
								
							
							
						
						
									
										27
									
								
								blocks.go
									
										
									
									
									
								
							|  | @ -1,5 +1,30 @@ | |||
| package defrag | ||||
| 
 | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| ) | ||||
| 
 | ||||
| func Blocks(diskMap []byte) ([]byte, error) { | ||||
| 	return nil, nil | ||||
| 	current := 0 | ||||
| 	onFile := false | ||||
| 	buff := bytes.Buffer{} | ||||
| 	for _, by := range diskMap { | ||||
| 		count, err := strconv.Atoi(string(by)) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 		onFile = !onFile | ||||
| 		if count == 0 { | ||||
| 			continue | ||||
| 		} | ||||
| 		append := "." | ||||
| 		if onFile { | ||||
| 			append = strconv.Itoa(current) | ||||
| 			current++ | ||||
| 		} | ||||
| 		buff.WriteString(strings.Repeat(append, count)) | ||||
| 	} | ||||
| 	return buff.Bytes(), nil | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue